有人能帮助我吗? 这就是我想要做的。我有一张桌子:
**tblColors**
id color_name
1 red
2 blue
3 white
4 white
5 blue
6 red
7 blue
8 white
9 red
10 blue
例如,我接受3个用户输入,即:
红色的
蓝色
3.白色
我想知道我的数据库中有多少套这三种颜色。 (红 - 蓝 - 白)
在我的示例数据库中,答案应该是:
**tblColors**
id color_name
------------------>id 1-3 is my first set of (red-blue-white)
1 red
2 blue
3 white
------------------
4 white
5 blue
-------------------------->id 6-8 is my second set
6 red
7 blue
8 white
--------------------------
9 red
10 blue
我在我的数据库中设置了2(红 - 蓝 - 白),因此结果应为:2
对不起,问题的描述不是很清楚,但我希望你能得到这个。
答案 0 :(得分:2)
SELECT COUNT(*)
FROM tblColors T1
LEFT JOIN tblColors T2
ON T1.id = T2.id - 1
LEFT JOIN tblColors T3
ON T2.id = T3.id - 1
WHERE T1.color_name + '-' +
T2.color_name + '-' +
T3.color_name = 'red-blue-white'
<强> Fiddler Demo 强>