SELECT DISTINCT dept+itemcode as Itemcode
FROM [bjreport].[dbo].DailySales201412
where storename in ('081')
and salesdate = convert(varchar(10),getdate()-1,1)
and dept+itemcode in ('10031387','10311005','10330005','10400980','10420102','10421011')
输出正常 即使重复也只显示单次
SELECT DISTINCT dept+itemcode as Itemcode,LRD
FROM [bjreport].[dbo].DailySales201412
where storename in ('081')
and salesdate = convert(varchar(10),getdate()-1,1)
and dept+itemcode in ('10031387','10311005','10330005','10400980','10420102','10421011')
一旦让不重复的第一列随机加一项LRD值 就所有重复的ITEMCODE号出来了,因为相同的ITEMCODE号有不同的LRD值
求解决不重复的ITEMCODE跟随机或第一个的LRD值
------解决思路----------------------
SELECT dept+itemcode as Itemcode,max(LRD) LRD
FROM [bjreport].[dbo].DailySales201412
where storename in ('081')
and salesdate = convert(varchar(10),getdate()-1,1)
and dept+itemcode in ('10031387','10311005','10330005','10400980','10420102','10421011')
group by dept+itemcode