select * from (select c.姓名,f_Get_Age(c.出生日期) as 年齡,decode(c.性別,'1','男','2','女') as 性別,c.身份證號,e.問題名稱,b.結束時間 as 出院日期,j.名稱,a.結帳金額
from 個人費用記錄 a ,服務活動記錄 b ,個人資訊 c,收入科目 j,個人問題串列 e
where a.個人id=b.個人id
and a.事件id=b.id
and b.摘要='個人入院記錄'
and a.個人id=c.id
and a.收入科目id=j.id
and e.個人id =a.個人id
and e.服務記錄id=b.id
and e.問題名稱 like '%術%'
and b.結束時間 between to_date('2015-01-01 00:00:00','yyyy-mm-dd hh24:mi:ss') and to_date('2018-01-01 00:00:00','yyyy-mm-dd hh24:mi:ss'))pivot (sum(a.結帳金額)for 名稱 in(select 收據費目 from 收入科目 ))
為什么sum里面寫“a.結賬金額”不行,但是寫“結賬金額”就行,還有in后面這個陳述句總是提示運算式缺失,
uj5u.com熱心網友回復:
1.為什么sum里面寫“a.結賬金額”不行,但是寫“結賬金額”就行,答:pivot統計的是內層表的結果集,a表是內層表的別名,pivot只能訪問結帳金額這個欄位。
就好比:
select
from (select a.結帳金額 from 表名 a)
where 。。。
where 條件只能使用內層結果集查詢處理的結帳金額這個欄位,無法使用a.任何欄位。
還有in后面這個陳述句總是提示運算式缺失,
2.in 后面智能使用欄位或變數,無法使用select結果集。這個是語法要求。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/60618.html
標籤:基礎和管理
