简体   繁体   English

基于 DB2 中的列值排序的查询

[英]query based on column value order by in DB2

I have the result in the following manner in the DB2. But, I'm looking to pull the details based on a column value which is matching with Y order我在 DB2 中以下列方式得到结果。但是,我希望根据与 Y 顺序匹配的列值提取详细信息

Name    Ind
----------------
syed    N
syed    Y
syed    N
shaik   Y
shaik   N
shaik   N

The output should be like output 应该是这样的

shaik   Y
shaik   N
shaik   N
syed    N
syed    Y
syed    N

The name values which are having Y first row as indicator should come as first.以 Y 第一行作为指示符的名称值应该排在第一位。

Any ideas有任何想法吗

This answers the original version of the question.这回答了问题的原始版本。

This sounds like two keys in an order by :这听起来像是order by两个键:

order by name, ind desc

Your question hints that you might want names with 'Y' anywhere to be first, suggesting that not all names might have 'Y' .您的问题暗示您可能希望在任何地方都带有'Y'名称是第一个,这表明并非所有名称都可能具有'Y' If this is the case, you can use window functions in the order by :如果是这种情况,您可以按以下order by使用 window 函数:

order by max(ind) over (partition by name) desc,  -- names with 'Y's first
         name,
         ind desc

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM