1樓:
select a.*, b.已填報, c.未填報
from
(--以業務統計
select d.matter,d.[type],d.
stardate,d.enddate from pz_plandetails d inner join pz_planexe e on e.planid = d.
planid
group by d.matter,d.[type],d.stardate,d.enddate) a,
full join(--已填報
select d.matter,count(*) as '已填報' from pz_plandetails d inner join pz_planexe e on e.planid = d.
planid
where [state] <> 10 group by d.matter) b on a.matter=b.matter
full join(--未填報
select d.matter,count(*) as '未填報' from pz_plandetails d inner join pz_planexe e on e.planid = d.
planid
where [state] = 10 group by d.matter) c on a.matter=c.matter
2樓:蒼穹陸帝
select d.matter,d.[type],d.
stardate,d.enddate,a.'已填報',b.
『未填報』 from pz_plandetails d inner join pz_planexe e on e.planid = d.planid join (
select d.matter,count(*) as '已填報' from pz_plandetails d inner join pz_planexe e on e.planid = d.
planid
where [state] <> 10 group by d.matter
)a on d.matter=a.matter join (
select d.matter,count(*) as '未填報' from pz_plandetails d inner join pz_planexe e on e.planid = d.
planid
where [state] = 10 group by d.matter
) b on d.matter=b.matter
group by d.matter,d.[type],d.stardate,d.enddate
3樓:匿名使用者
將你的三個查詢結果看作三個表然後聯合查詢就可以了啊!
sql查詢問題
1全部如果原表是 table1 a1,a2,a3 select a1,sum case when a2 1 and a3 是 then 1 else 0 end b1,sum case when a2 2 and a3 是 then 1 else 0 end b2,sum case when a2 ...
SQL日期查詢問題
假設我想查詢2013 12 23的資料,則sql語法如下 select from table where datediff dd,日期 2013 12 23 0 假設我想查詢2013 12 1到2013 12 25之間的資料,則如下 select from table where datediff ...
sql問題子查詢返回的值不止,sql 問題子查詢返回的值不止一個。
解決方法如下 返回一個值 返回多個說明資料庫中滿足使用者查詢條件的記錄有多個,要返回一個就說明使用者的查詢條件不夠,再加條件控制就行了,比如在語句末尾再加 and 如果使用者問的是如何在後臺程式中接收的話,用list可以,一個節點接收result的一行值,讀取的時候遍歷list就行了。update ...