我有一张如下表格
bill_id sonvinid tid date brandname
1000109201701 13413 1 2015-10-03 00:00:00.000 QED - TM
1000109201701 13741 1 2015-10-13 00:00:00.000 QED - TM
1000109201702 14258 1 2015-11-05 00:00:00.000 QED - TM
现在我想运行一个查询,其中bill_id不应重复,并且具有相同bill_id的重复列应显示为null
bill_id sonvinid tid date brandname
1000109201701 13413 1 2015-10-03 00:00:00.000 QED - TM
13741 1 2015-10-13 00:00:00.000 QED - TM
1000109201702 14258 1 2015-11-05 00:00:00.000 QED - TM
我知道我不能在这里使用不同的
那么,运行这种类型的select命令最好是什么查询?
答案 0 :(得分:2)
SELECT CASE WHEN row_num = 1 THEN bill_id ELSE NULL END AS bill_id
, sonvinid
, tid
, date
, brandname
FROM
( SELECT bill_id
, ROW_NUMBER() OVER (PARTITION BY bill_id ORDER BY date ASC) row_num
, sonvinid
, tid
, date
, brandname
FROM table1
) a;
无论如何,我同意肖恩的评论,这应该是在UI方面完成的