當前位置:首頁 » 編程語言 » sql視圖統計
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

sql視圖統計

發布時間: 2023-01-04 13:58:16

㈠ SQL三表統計成一張視圖。

這個有幾種寫法,我就寫一種相對比較好理解的。
select 表1.id,表1.內容,a.表2金額,b.表3金額,a.表2金額+b.表3金額 總額 from
表1,
(select id,sum(金額) 表2金額 from 表2 group by id) a,
(select id,sum(金額) 表3金額 from 表3 group by id) b where 表1.id=b.id and 表1.id=a.id

㈡ SQL 通過視圖進行統計,總數量可以統計但是沒有消耗的怎麼才能顯示為消耗為0呢

使用FORMAT函數,格式化顯示

㈢ SQl語句如何對select的結果進行分類統計(或者說如何用視圖實現統計查詢)

直接下面一句話就可以了:
select 單位名稱,count(case 項目類別 when '理工類' then 1 end) 理工類,
count(case 項目類別 when '社科類' then 1 end) 社科類,
count(case 項目性質 when '橫向' then 1 end) 橫向,
count(case 項目性質 when '縱向' then 1 end) 縱向,
count(case 項目性質 when '校外' then 1 end) 校外,
count(*) 總數
from Item_Info
groupo by 單位名稱

㈣ MS SQL 多表統計視圖問題

你的信息給的不全,不知我理解對不對
CREATE VIEW V_BUY_ADJUST
AS select a.客戶姓名, d.客戶等級名稱, count(b.總金額) 訂單總金額, count(e.成本金額) 總成本,
count(b.總金額-e.成本金額+c.回款金額) 總利潤, count(*) 訂單數, count(c.回款金額) 總回款
from 客戶信息表 A
left join 客戶訂單表 B on a.客戶id=b.客戶id
left join 客戶回款信息表 C on b.訂單id=c.訂單id
left join 客戶等級表 D on a.客戶id=d.客戶id
left join 成本信息表 E on a.客戶id=e.客戶id
group by a.客戶姓名, d.客戶等級名稱
如果還有問題可以寫在問題補充里