當前位置:首頁 » 操作系統 » 資料庫求和

資料庫求和

發布時間: 2022-01-09 12:08:14

A. sql 求和語句

select
sum(*)
from
(SELECT
SUM(zy_detail_charge.charge_amount)
FROM
zy_detail_charge
where
zy_detail_charge.charge_code
in
(select
fee_code
from
or_level
where
or_level
=
'xt'
and
flag
=
'410')
and
data_month
='2010-08'
union
all
SELECT
SUM(mz_charge_detail.quantity)
from
mz_charge_detail
where
mz_charge_detail.charge_item_code
in
(select
fee_code
from
or_level
where
or_level
=
'xt'
and
flag
=
'410'))

B. SQL資料庫求和

select 姓名 as 姓名,max(case 課程 when'語文' then 分數 else 0 end)語文,max(case 課程 when'數學' then 分數 else 0 end)數學,max(case 課程 when'物理' then 分數 else 0 end)物理 from tb group by 姓名
union all
select '' 姓名 ,sum(語文),sum(數學),sum(物理) from (
select 姓名 as 姓名,max(case 課程 when'語文' then 分數 else 0 end)語文,max(case 課程 when'數學' then 分數 else 0 end)數學,max(case 課程 when'物理' then 分數 else 0 end)物理 from tb group by 姓名
) a

C. sql 求和

想了一下,這個最好是把兩個表union起來再求和!

直接連接的話需要全外連接比較困難.
qq82296344的答案不對,假如b表有一個lx值不在a表中出現,這個lx就會遺漏的!

關於group by出錯的問題:我加了一個別名test1,你再試試。再不行改成as test1

select lx, sum(money), sum(salary) from
(select lx, money, 0.0 as salary from a
union all
select lx, 0.0 as money, salary from b) test1
group by lx;

D. sql對查詢結果求和

作為兩個子查詢再查一次就行了
select isnull(t1.[詳情],t2.[詳情]) AS [詳情],
ISNULL(t1.[次數], 0) AS [贈_次數],
ISNULL(t2.[次數], 0) AS [送_次數],
ISNULL(t1.[次數], 0) + ISNULL(t2.[次數], 0) AS [總次數]
FROM
(....) AS t1
FULL OUTER JOIN
(....) AS t2
ON t1.[詳情]=t2.[詳情]

E. SQL里邊的求和語句怎麼寫

SQL中求和語句分為縱向匯總和橫向匯總語句;

假設數據列為:A、B、C、D、E、F、G

縱向匯總語句:

select sum(A),sum(B),sum(C),sum(D),sum(E),sum(F),sum(G) from 表名

橫向匯總的SQL語句是:
select A,B,C,D,E,F,G,A+B+C+D+E+F+G from 表名

求所有數據總和的SQL語句是:
select sum(A)+sum(B)+sum(C)+sum(D)+sum(E)+sum(F)+sum(G) from 表名

(5)資料庫求和擴展閱讀:

SQL是一種查詢功能很強的語言,只要是資料庫存在的數據,總能通過適當的方法將它從資料庫中查找出來。SQL中的查詢語句只有一個:SELECT,它可與其它語句配合完成所有的查詢功能。SELECT語句的完整語法,可以有6個子句。完整的語法如下:

SELECT 目標表的列名或列表達式集合

FROM 基本表或(和)視圖集合

〔WHERE條件表達式〕

〔GROUP BY列名集合

〔HAVING組條件表達式〕〕

〔ORDER BY列名〔集合〕…〕

F. SQL按條件匯總求和

如下:

1、第一步,將示例表導入SQL語句中,見下圖,轉到下面的步驟。

G. SQL資料庫求和

select a.姓名,a.考號,a.考點號,a.考場號,(a.客觀成績 + b.主觀成績) as 總成績,(a.客觀成績 + b.主觀成績) / 2 as 平均分,a.座位號 from A表 a left join B表 b on a.考號 = b.考號
where b.缺考 <> 缺考

H. 資料庫求和的問題

用sql server的SQL,建一個表:
create table 成績(語文 decimal(4,1),英語 decimal(4,1),數學 decimal(4,1),總分 as 語文+英語+數學)
即可達到目的。

I. 資料庫分組求和的寫法

select B,sum(C),sum(D),sum(E),sum(F),G from DDD where group by (B,G)
保准正確得到你想要的!

J. sql語句求和

SQL中求和語句分為縱向匯總和橫向匯總語句;

假設數據列為:A、B、C、D、E、F、G

縱向匯總語句:

selectsum(A),sum(B),sum(C),sum(D),sum(E),sum(F),sum(G)from表名

橫向匯總的SQL語句是:

selectA,B,C,D,E,F,G,A+B+C+D+E+F+Gfrom表名

求所有數據總和的SQL語句是:

selectsum(A)+sum(B)+sum(C)+sum(D)+sum(E)+sum(F)+sum(G)from表名

結構化查詢語言是高級的非過程化編程語言,允許用戶在高層數據結構上工作。它不要求用戶指定對數據的存放方法,也不需要用戶了解具體的數據存放方式,所以具有完全不同底層結構的不同資料庫系統, 可以使用相同的結構化查詢語言作為數據輸入與管理的介面。

(10)資料庫求和擴展閱讀:

sql參考語句

刪除新表

drop table tabname

增加一個列

Alter table tabname add column col type

添加主鍵

Alter table tabname add primary key(col)

刪除主鍵

Alter table tabname drop primary key(col)

創建索引

create [unique] index idxname on tabname(col….)

熱點內容
實測華為編譯器 發布:2024-09-19 23:50:52 瀏覽:821
linux匯總 發布:2024-09-19 23:46:39 瀏覽:452
阿里雲伺服器環境搭建教程 發布:2024-09-19 23:21:58 瀏覽:837
黃色文件夾圖標 發布:2024-09-19 23:19:22 瀏覽:684
mysql資料庫導出導入 發布:2024-09-19 23:00:47 瀏覽:183
lua腳本精靈 發布:2024-09-19 23:00:41 瀏覽:659
任務欄文件夾圖標 發布:2024-09-19 22:54:25 瀏覽:101
解壓來一波 發布:2024-09-19 22:46:36 瀏覽:933
mysqlpythonubuntu 發布:2024-09-19 22:46:27 瀏覽:501
伺服器請求獲取ip地址 發布:2024-09-19 22:33:25 瀏覽:515