我的表格在这里给出了......
Appear Back_Color Fore_Color
simple White Black
simple white Black
medium Gray Black
medium Gray Black
现在我想检索所有没有出现的记录..
即结果应该是这样的......
Appear Back_Color Fore_Color count
simple White Black 2
medium Gray Black 2
这里可以使用哪些代码?
谢谢和问候, Nijisha K C
答案 0 :(得分:0)
也许是这样的:
SELECT Appear, Back_Color, Fore_Color, COUNT(*) AS count
FROM Table1
GROUP BY Appear, Back_Color, Fore_Color
<强>更新强>
考虑您提供的测试数据:
DECLARE @tbl TABLE(Appear VARCHAR(10),Back_Color VARCHAR(10),
Fore_Color VARCHAR(10))
INSERT INTO @tbl
VALUES
('simple','White','Black'),
('simple','white','Black'),
('medium','Gray','Black'),
('medium','Gray','Black')
使用此查询:
SELECT Appear, Back_Color, Fore_Color, COUNT(*) AS count
FROM @tbl
GROUP BY Appear, Back_Color, Fore_Color
输出如下:
Appear Back_Color Fore_Color count
medium Gray Black 2
simple White Black 2
就像你期望的那样