我有3张桌子。 查询条件:
Need to get number of Source_Id with status_id=1
Need to get number of Source_Id with status_id=3 except status_id=1
Need to get number of Source_Id with status_id=2 except status_id=1 and 3
表1:状态
**Satus_Id Status**
1 Matching
2 Not Matching
3 Manual Matching
表2:来源详情
**Source_Id Name Date**
1 Name1 21-01-2013
2 Name2 22-01-2013
3 Name3 22-01-2013
4 Name4 23-02-2013
表3:来源
**Id Source_Id Satus_Id**
1 1 1
2 1 2
3 1 3
4 2 2
5 2 3
6 3 3
7 4 2
预期输出为
**Status Count**
Matching 1
Manual Matching 2
Not Matching 1
答案 0 :(得分:1)
SELECT ALLCOLUMNSYOUWANTTOUSE
FROM TABLE YOU WANT
WHERE FIRST
UNION
SELECT SAMECOLMNS
FROM TABLE
WHERE SECOND
UNION
SELECT SAMECOLUMNS
FROM TABLE
WHERE THIRD
关键是在每个中使用相同的列。
如果这不起作用,请显示查询和表格,我们可以为您进行加入