SQL 查詢問題
如下,   有三個Item相同,   但ld_qty_oh數量我們只想顯示一次(顯示在promise   date最前的Item上),   剩下的兩個可為空,    
 item                  ld_qty_oh 
 item0                        10 
 item0                        10 
 item0                        10 
 item0                        10 
 item1                        20 
 item1                        20 
 item1                        20 
 我想顯示成這樣怎么顯示 
 item                  ld_qty_oh 
 item0                        10 
 item0                         
 item0                         
 item0                         
 item1                        20 
 item1                         
 item1                           
 想顯示成這樣怎么顯示
------解决方案--------------------如果是通过程序来约束显示,完全可以在客户端处理。
------解决方案--------------------  沒有主鍵,借用臨時表吧   
 Select ID = Identity(Int, 1, 1), * Into #T From 表   
 Select 
 	Distinct  
 	A.item, 
 	(Case When A.ID != B.ID Then Null Else ld_qty_oh End) As ld_qty_oh 
 From 
 	#T A 
 Inner Join 
 	(Select item, Min(ID) As ID From #T Group By item) B 
 On A.item = B.item   
 Drop Table #T
------解决方案--------------------這個東西,用SQL實現不是很好,最好在前台去控制。
------解决方案--------------------如果记录重复出现就替换为空,如果没有就显示 
 比如 
 序号   货物  数量 
  1      A     30 
  2             10 
  3             -5 
  4      B      20 
  5             100 
  6      C      1 
  7             98     
 declare @t table(序号 int,货物 varchar(100),数量 int) 
 insert into @t 
 select  1,       'A ' ,   30 union 
 select 2  ,      'a '  ,    10 union 
 select 3  ,    'a '    ,    -5 union 
 select 4  ,    'B '  ,    20 union 
 select 5  ,     'b '  ,     100 union 
 select 6  ,     'C '  ,    1 union 
 select 7  ,      'c '  ,    98      
 select 序号,case when 序号=(select min(序号) from @t where 货物=a.货物) then 货物 else  ' ' end as 货物,  数量 
 from @t a 
 order by 序号 
------解决方案----------------------建立测试环境 
 create table #tb(item varchar(10),ld_qty_oh int) 
 insert #tb(item,ld_qty_oh) 
 select  'item0 ', '10 ' union all 
 select  'item0 ', '10 ' union all 
 select  'item0 ', '10 ' union all 
 select  'item0 ', '10 ' union all 
 select  'item1 ', '20 ' union all 
 select  'item1 ', '20 ' union all 
 select  'item1 ', '20 ' 
 go 
 --执行测试语句 
 select identity(int,1,1) as id,t.item,t.ld_qty_oh into #tmp from #tb t 
 select item,case when exists(select 1 from #tmp where t.item = item and t.ld_qty_oh = ld_qty_oh and t.id >  id) then null else ld_qty_oh end as ld_qty_oh 
 from #tmp t 
 go 
 --删除测试环境 
 drop table #tb,#tmp 
 go 
 /*--测试结果 
 item       ld_qty_oh    
 ---------- -----------