假设我有一张这样的表..
ColA ColB ColC
----------------------
A 100 1
A 200 2
A 300 3
B 100 1
B 200 2
C 300 1
我必须选择COLA,其中100 = 1且200 = 2且300 = 3
请帮忙
答案 0 :(得分:3)
从我的问题中我可以理解,你需要一些简单的东西:
select COLA where ( (COLB=100 and COLC=1) or (COLB=200 and COLC=2) or (COLB=300 and COLC=3) )
或者更为一般:
select COLA where COLB = COLC*100
答案 1 :(得分:2)
SELECT ColA
FROM my_table
WHERE ColB = (ColC * 100);
答案 2 :(得分:0)
有几种方法可以解决这个问题,但这可能是最简单的方法,而且考虑到你的选择,它会表现得相当不错:
SELECT ColA
FROM MyTable
WHERE (ColB = 100 AND ColC = 1)
OR (ColB = 200 AND ColC = 2)
OR (ColB = 300 AND ColC = 3)
GROUP BY ColA
HAVING COUNT(*) = 3