sql - 在同一个表上加入多个过滤的选择查询?

标签 sql

我是一个完整的 sql noob,所以我为接下来的 sql 屠杀道歉......
这是我要执行的操作的伪代码:

count( 
   join( 
      select( * from table X where a='stuff' and b='junk' ) as X1
      select( * from table X where a='arg' and b='blarg' ) as X2
      select( * from table X where a='narf' and b='foo' ) as X3
   ) where X1.c = X2.c = X3.c
)

是否可以在一次查询中获得此结果?

最佳答案

select count(*) from 

(select * from table X where a='stuff' and b='junk') x1

join

(select * from table X where a='arg' and b='blarg' ) x2

on x1.c=x2.c

join

( select * from table X where a='narf' and b='foo' ) X3

on x2.c=x3.c

关于sql - 在同一个表上加入多个过滤的选择查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12714682/

相关文章:

java - 从oracle数据库获取日期而不从列中获取时间

sql - 索引可用时进行全表扫描

mysql - 从表中删除 WHERE NOT MAX

sql - Oracle 8i 中的四表连接

sql - 如何检测哪些存储过程更新或插入某个表?

sql - 什么时候引用完整性不合适?

mysql - 如何创建与 Fusion Tables "summarize"函数等效的 MySQL 查询?

sql - 聚合还是不聚合,这是数据库模式设计的问题

mysql - 如何取消选择mysql中的类似值

java - Sqlite约束异常错误