如何(或可以)在多列上选择DISTISTION?我需要从一个表中检索所有行,其中两个列的合并都是不同的。因此,我希望所有的销售,没有任何其他销售发生在同一天,以相同的价格。基于日和价格的独特销售将被更新到活动状态。所以我在想:UPDATE salesSET status = 'ACTIVE'WHERE id IN (SELECT DISTINCT (saleprice, saledate), id, count(id)
FROM sales HAVING count = 1)但我的大脑会痛得更厉害。
3 回答
眼眸繁星
TA贡献1873条经验 获得超9个赞
SELECT DISTINCT a,b,c FROM t
SELECT a,b,c FROM t GROUP BY a,b,c
UPDATE salesSET status='ACTIVE'WHERE id IN( SELECT id FROM sales S INNER JOIN ( SELECT saleprice, saledate FROM sales GROUP BY saleprice, saledate HAVING COUNT(*) = 1 ) T ON S.saleprice=T.saleprice AND s.saledate=T.saledate )
慕桂英3389331
TA贡献2036条经验 获得超8个赞
UPDATE salesSET status='ACTIVE'WHERE id IN ( SELECT MIN(id) FROM sales GROUP BY saleprice, saledate HAVING COUNT(id) = 1)
添加回答
举报
0/150
提交
取消