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

sql統計兩種狀態下兩個和

發布時間: 2023-02-01 02:31:12

sql中如何將兩個查詢結果相加

做個簡單的。
兩個數據表db1,db2

查詢結果A是從數據表db1獲取的:
select names, sale from db1

查詢結果B是從數據表db2獲取的:
select names, sale from db2

則查詢結果C:

select names,sum(sale) as sale
from
(select names, sale from db1
union
select names, sale from db2
)
group by names

Ⅱ SQL怎麼統計個數

方法一:

SELECT SUM(正確數)+SUM(錯誤數) AS 總記錄數,SUM(正確數),SUM(錯誤數)
FROM (
SELECT COUNT(1) 正確數,0 錯誤數
FROM TB
WHERE STATUS=1
UNION ALL
SELECT 0 正確數,COUNT(1) 錯誤數
FROM TB
WHERE STATUS=0) a

方法二:

select count(1)總記錄數,sum(case when status=1 then 1 else 0 end)正確數,sum(case when status=0 then 1 else 0 end) 錯誤數 from T

Ⅲ sql 分類匯總查詢語句

select dept as 部門,sum(pay) as 合計,sum(case zt when '01'then 1 else 0 end) as 個數(01狀態),
sum(case zt when '02'then 1 else 0 end) as 個數(02狀態),count(*) as 總數
from 表 group by dept

以上,希望對你有所幫助

Ⅳ SQL 如何對二個欄位中的數字相加得到總數

SQL 語句使用 『+』號將兩個欄位的數值相加

例,表格 tt

Ⅳ SQL 兩表統計求和怎麼寫

用inner join 連接起來即可
語句:
select a.出庫單號,a.品牌,a.區域,a.數量,a.分配數量,b.裝箱數量
from 出庫單 a inner join 裝箱明細 b on a.出庫單號=b.出庫單號