本文介绍了分组IN语句sql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有一个名为 table1 的表,它对应的列是 col1、col2、col3 和 col4.
lets say I have a table called table1 and it's corresponding columns are col1, col2, col3 and col4 for example.
什么是等效的事情:
-- note that the following query will not work
SELECT *
FROM table1
WHERE col1, col2 IN (SELECT col1, col2
FROM table1
WHERE col3 < 4)
我是否必须在我的数据库中合并 col1 和 col2 才能完成这项工作?如果我将 col1 和 col2 合并到 col1_2 中,那么我将能够通过编写上述查询:
Do I have to merge col1 and col2 in my database to make this work? If I merge col1 and col2 into col1_2 then I will be able to make the above query work by writing:
SELECT *
FROM table1
WHERE col1_2 IN (SELECT col1_2
FROM table1
WHERE col3 < 4)
IN 子句在使用一列时工作正常.如果我可以将它与多个列一起使用而不必修改数据库,那就太好了.
The IN clause works fine when using one column. it will be nice if I could use it with several columns without having to modify the database.
推荐答案
SELECT * from table1 t1, table1 t2
where t1.col1=t2.col1 and t1.COl2=t2.Col2 and t1.col3<4
试试这个
这篇关于分组IN语句sql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!