假设一个表如下摘录所示:
ITEID | 颜色代码 | SIZEPOS | ISEAN13 |
---|---|---|---|
4454 | 7 | 0 | |
4454 | 0 | ||
4456 | 0 | ||
4456 | 0 | ||
4456 | 0 | ||
4456 | 0 | ||
4462 | 0 | ||
4462 | 0 | ||
4462 | 0 | ||
4462 | 0 | ||
4462 | 0 | ||
4462 | 0 | ||
4462 | 0 | ||
4464 | 0 | ||
4464 | 0 | ||
4464 | 0 | ||
4469 | 0 | ||
4469 | 0 | ||
4469 | 0 | ||
4469 | 0 | ||
4511 | 0 | ||
4511 | 0 | ||
4511 | 0 | ||
4511 | 0 | ||
4511 | 0 |
可能吗?(请下次自己做设置工作)
DROP TABLE IF EXISTS YT
CREATE TABLE YT(
ITEID INT NOT NULL
,COLORCODE NVARCHAR(7)
);
INSERT INTO YT(ITEID,COLORCODE) VALUES
(4454,N'ΜΑΥ'),(4454,N'ΜΑΥ'),(4456,N'ΜΑΥ Λ'),(4456,N'ΜΑΥ Λ'),(4456,N'ΜΑΥ Λ')
,(4456,N'ΜΑΥ Λ'),(4462,N'ΜΑΥ'),(4462,N'ΜΑΥ'),(4462,N'ΜΑΥ'),(4462,N'ΜΑΥ')
,(4462,N'ΜΑΥ'),(4462,N'ΜΑΥ'),(4462,N'ΜΑΥ'),(4464,N'ΜΑΥ ΠΡΑ'),(4464,N'ΜΑΥ ΠΡΑ')
,(4464,N'ΜΑΥ ΠΡΑ'),(4469,N'ΜΠΛΕ'),(4469,N'ΜΠΛΕ'),(4469,N'ΜΠΛΕ'),(4469,N'ΜΠΛΕ')
,(4511,N'ΚΟΚ'),(4511,N'ΚΟΚ'),(4511,N'ΚΟΚ'),(4511,N'ΚΟΚ'),(4511,N'ΚΟΚ')
-- ADDED DATA TO DEMONSTRATE YOUR QUESTION
,(4511,N'ΚΟΚ'),(4511,N'BAL'),(4511,N'NIK'),(4511,N'DIK'),(4511,N'ΚIΚ')
;
SELECT ITEID, COUNT(DISTINCT COLORCODE) AS cnt
FROM YT
GROUP BY ITEID
HAVING COUNT(DISTINCT COLORCODE) > 1