当其中两行需要唯一时选择三行 (SQL)

发布于 2024-09-19 04:39:28 字数 300 浏览 7 评论 0原文

首先,我使用的是 Oracle 10g Express

所以我想选择三列:

[domain_name] [index_path] [collection_name]

现在有两列我想要唯一:

[domain_name] [index_path]

所以我的问题是我基本上如何:

select unique domain_name, index_path from TABLENAMEHERE

同时选择列 [collection_name]

First of all I am using Oracle 10g Express

So there are three columns I want to select:

[domain_name] [index_path] [collection_name]

Now there are two columns that I want to be unique:

[domain_name] [index_path]

So my issue is how do I basically:

select unique domain_name, index_path from TABLENAMEHERE

while also selecting the column [collection_name]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

绝對不後悔。 2024-09-26 04:39:28

如果domain_name、index_path 的某些组合有多行,那么您希望从这些行中看到collection_name 的什么值?如果您不介意哪个值,请执行以下操作:

SELECT domain_name, index_path, MIN(collection_name) collection_name
FROM TABLENAMEHERE
GROUP BY domain_name, index_path;

If there are multiple rows for some combinations of domain_name, index_path then what value of collection_name would you want to see from those rows? If you don't mind which value then do:

SELECT domain_name, index_path, MIN(collection_name) collection_name
FROM TABLENAMEHERE
GROUP BY domain_name, index_path;
为你鎻心 2024-09-26 04:39:28
select domain_name, index_path, collection_name
  from my_table outr
       inner join 
         (select domain_name, index_path, collection_name, 
                 max(gen_timestamp) 
                    over (partition by domain_name, index_path) gen_timestamp
            from my_table) innr
 where outr.domain_name = innr.domain_name
   and outr.index_path  = innr.index_path
   and outr.collection_name = innr.collection_name
   and outr.gen_timestamp   = innr.gen_timestamp
select domain_name, index_path, collection_name
  from my_table outr
       inner join 
         (select domain_name, index_path, collection_name, 
                 max(gen_timestamp) 
                    over (partition by domain_name, index_path) gen_timestamp
            from my_table) innr
 where outr.domain_name = innr.domain_name
   and outr.index_path  = innr.index_path
   and outr.collection_name = innr.collection_name
   and outr.gen_timestamp   = innr.gen_timestamp
零度° 2024-09-26 04:39:28

只需在查询中将 unique 替换为 distinct 即可。

哦...

那应该是这样的:

select [domain_name], [index_path], min([collection_name]) 
from TABLENAMEHERE
group by [domain_name], [index_path]

Just replace unique with distinct in your query.

Oh...

Then it should be like this:

select [domain_name], [index_path], min([collection_name]) 
from TABLENAMEHERE
group by [domain_name], [index_path]
橘味果▽酱 2024-09-26 04:39:28

您可以按domain_name 和index_path 进行分组,并在每组中包含一个(最小值或最大值)collection_name 值。

You can group by the domain_name and index_path and include ONE (min or max) value of collection_name per group.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文