當前位置:九游会j9娱乐平台-九游ag登录中心网址 » 編程語言 » 統計sql

統計sql-九游会j9娱乐平台

發布時間: 2022-01-07 23:39:14

1. sql統計語句有哪些

sql語言誕生有一段時間了,裡面有一些自帶的很方便的函數,對於操作資料庫來說是非常方便的,下面就介紹幾種統計。

2. sql語句 查詢 統計

這幾個表裡有哪幾個列要告訴我們呀!
hotyxm - 高級魔法師 六級 最後一個題目好像有誤.應該是:
select 學生姓名,count(課程編號) from 選課表 group by 學生號having count(課程編號)>=4;

不過你還是要把這幾個表詳細說下才好,上面這個sql語句是跟據一般可能有和列和表來寫的.
hotyxm - 高級魔法師 六級的回答可能還有其它錯誤.我沒細看.但好像他就是從學生表裡來查東西,一個表怎麼能有那麼多東西,會出異常的.

你不詳細說明一下有哪些表和哪些列,我也不好跟你寫.

3. sql語句統計查詢結果數量怎麼寫

可以通過count函數來實現。

sqlone:select * from tablename1 where id>5;此語句查詢出來多條記錄,之後看做一個新的表。

sqltwo:select conut(*) from (select * from tablename1 where id>5) as tablename2;此語句即可查詢出來統計的記錄條數。

備註:以上方法通用於所有的數據統計,如果是單表查詢,可以直接通過:「select count( *) from tablename1 where id>5"的形式查詢出結果。

4. sql 統計數量

--表a和表b分開來統計,最後合並兩個統計結果
時間在一個范圍內用 時間a between '時間1' and '時間2'
由於不是很明白你的分組統計原則,所以group by語句暫時無法提供建議

5. sql怎麼統計個數

不同資料庫的系統表可能不一樣,比如informix就是systables

tabname。
informix資料庫:
統計個數:
select
count(*)
from
systables
where
tabname
like
'�c%'
查看錶:
select
tabname
from
systables
where
tabname
like
'�c%'
其他資料庫的話,系統表可能是sysobjects,對應的列可能也有不同,看你的情況改吧。

6. sql統計查詢

如果只有這3個固定日期.可以教你一個簡單行轉列的方法。
但如果日期是隨機的,那就要用到動態sql了.

先寫出簡單的來.
select name,
sum(case when date = '2008-1-12' then 1 else 0 end) as 2008-1-12,
sum(case when date = '2008-1-13' then 1 else 0 end) as 2008-1-13,
sum(case when date = '2008-1-16' then 1 else 0 end) as 2008-1-16
from tablename group by name

下面是按照上面例子中寫出的動態sql語句.

create table tba
(
id int,
date datetime,
name varchar(10)
)
go

insert into tba
select 1,'2008-1-12', 'a' union all
select 2,'2008-1-12', 'b' union all
select 3,'2008-1-13', 'a' union all
select 4,'2008-1-13', 'a' union all
select 5,'2008-1-16', 'b'

create table #tmp
(
id int identity(1,1),
date datetime
)
declare @strsql varchar(8000)
declare @id int,@rowcount int, @date datetime

insert into #tmp(date) select convert(varchar(10),date,23) from tba group by convert(varchar(10),date,23)
select @rowcount = @@rowcount,@id = 1
select @strsql = 'select name'
while @id <= @rowcount
begin
select @date = date from #tmp where id = @id
select @strsql = @strsql ',sum(case date when ''' convert(varchar(10),@date,23) ''' then 1 else 0 end) as [' convert(varchar(10),@date,23) ']'
select @id = @id 1
end
select @strsql = @strsql ' from tba group by name'
exec(@strsql)
drop table #tmp
go

7. sql 統計數量

select 學生表.學號, 選課數 into 選課數統計表 from 學生表 left join (select 學號, count(*) as 選課數 from 學生選課表 group by 學號) tmbdb on 學生表.學號=tmpdb.學號

8. sql統計數量

select 部門名稱,count(id) as '員工人數 ' from a inner join b on b.a_id=a.id

9. 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

熱點內容
仙境傳說手游腳本 發布:2024-07-17 16:09:24 瀏覽:690
matlab命令窗口和新建腳本 發布:2024-07-17 15:51:26 瀏覽:374
建ftp文件夾 發布:2024-07-17 15:51:26 瀏覽:954
魔獸撿物腳本 發布:2024-07-17 15:27:56 瀏覽:129
開發ip伺服器 發布:2024-07-17 15:24:42 瀏覽:387
安卓系統視頻製作哪個好用 發布:2024-07-17 15:10:47 瀏覽:210
androidapk結構 發布:2024-07-17 15:10:43 瀏覽:945
c語言指針的例子 發布:2024-07-17 15:08:01 瀏覽:768
linuxzcat 發布:2024-07-17 15:02:09 瀏覽:901
賓士編程嗎 發布:2024-07-17 14:57:08 瀏覽:853
网站地图