此处我具有发票明细表。 我需要所有值不重复[invoiceno]
。 我尝试DISTINCT不适用于MSSQL中的SELECT查询
select distinct invoiceno,name,addr1,addr2,id from invoice_table;
结果:
invoiceno name addr1 addr2 id
2016718001 Severus Sanpe 7,Hogwards, Sevilee,USA 7451 5
2016718002 Severus Sanpe 7,Hogwards, Sevilee,USA 7451 8
2016718002 Severus Sanpe 7,Hogwards, Sevilee,USA 7451 9
我想要的结果:
invoiceno name addr1 addr2 id
2016718001 Severus Sanpe 7,Hogwards, Sevilee,USA 7451 5
2016718002 Severus Sanpe 7,Hogwards, Sevilee,USA 7451 8
它在SELECT
做工精细没有id
。但我也需要这个。 如何做到这一点?
看到ID,它是9项第3。 –
id列是不同的,这是它出现两次的原因 – leetibbett
“distinct”在整行上工作,因此它发生两次。该行是唯一的。 –