sql語句,完成安部門統計每月記錄數。入下表

時間 2022-08-31 14:15:13

1樓:匿名使用者

select sum(case month(時間) when 1 then 1 else 0) as '1月',

sum(case month(時間) when 2 then 1 else 0) as '2月',

sum(case month(時間) when 3 then 1 else 0) as '3月',

sum(case month(時間) when 4 then 1 else 0) as '4月',

sum(case month(時間) when 5 then 1 else 0) as '5月',

sum(case month(時間) when 6 then 1 else 0) as '6月',

sum(case month(時間) when 7 then 1 else 0) as '7月',

sum(case month(時間) when 8 then 1 else 0) as '8月',

sum(case month(時間) when 9 then 1 else 0) as '9月',

sum(case month(時間) when 10 then 1 else 0) as '10月',

sum(case month(時間) when 11 then 1 else 0) as '11月',

sum(case month(時間) when 12 then 1 else 0) as '12月',

部門名稱

from 表名

group by 部門名稱

2樓:匿名使用者

with a

as(select 部門名稱,month(時間) as 時間 ,count(記錄) as ji from table1 group by 部門名稱,month(時間) )

select 部門名稱 ,(case 時間 when '2' then ji else 0 end) as 一月,

(case 時間 when 2 then ji else 0 end)二曰,

(case 時間 when 3 then ji else 0 end)三,

```````

from a

sql語句 查詢記錄數

3樓:匿名使用者

sql中查詢記錄數用count函式。

1、建立測試表,插入資料:

create table test

(id int)

insert into test values (1)insert into test values (2)insert into test values (3)insert into test values (null)2、查詢記錄數為兩種,一種是count(*),一種是count(欄位值):

測試一:

select count(*) from test結果:測試二:

select count(id) from test結果:說明:如果count(欄位名)的欄位中含有空值,則在count中不計數,而count(*)則是查詢全部的行數。

4樓:順德迷途羔羊

top 50是查詢前面50個記錄,而不是查詢數量

select top 50 * from table where 欄位 is null

5樓:匿名使用者

declare @n int

set @n = 500

set rowcount @n

select * from table_name這樣,查詢結果將等同於

select top 50 from table_name

6樓:匿名使用者

select count(*) from (select top 50 * from table) a where 欄位=''

用sql語句進行查詢統計性別,資料表如下 5

7樓:鬼谷子教主

select province

,總人數

,男,女

,case 女 when 0 then 0 else 男/女 end as 男女比例

from (

select province

,count(*) as 總人數

,sum(case gender when '男' then 1 else 0 end) as 男

,sum(case gender when '女' then 1 else 0 end) as 女

group by province)

oracle資料庫 ,想統計一個使用者下,所有表的記錄的總條數,用什麼語句可以實現?

如何統計sql語句查詢出來的條數?

8樓:匿名使用者

可以通過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"的形式查詢出結果。

9樓:千鳥

i=select  count(1)   from table

語句返回值即為查詢出來的條數.

示例如圖所示:

擴充套件:count() 函式返回匹配指定條件的行數。

語法(1). sql count(column_name) 語法

count(column_name) 函式返回指定列的值的數目(null 不計入):

select count(column_name) from table_namesql

(2). count(*) 語法

count(*) 函式返回表中的記錄數:

select count(*) from table_namesql

(3). count(distinct column_name) 語法

count(distinct column_name) 函式返回指定列的不同值的數目:

select count(distinct column_name) from table_name

10樓:匿名使用者

select conut(*) from tablename

11樓:匿名使用者

*改為count(*)就返回記錄條數了,當然也可以用recordset的count屬性

sql 語句怎麼寫根據選擇的年份統計出該年下每個月的訂單總數

12樓:匿名使用者

這是一些統計每天、每月、每年的銷售總額的查詢語句,給你參考:

1、每年

select year(ordertime) 年,sum(total) 銷售合計

from 訂單表

group by year(ordertime)2、每月

select year(ordertime) 年,month(ordertime) 月,

sum(total) 銷售合計

from 訂單表

group by year(ordertime),month(ordertime

3、每日

select year(ordertime) 年,month(ordertime) 月,

day(ordertime) 日,

sum(total) 銷售合計

from 訂單表

group by year(ordertime),month(ordertime),

day(ordertime)

另外每日也可以這樣:

select convert(char(8),ordertime,112) dt,

sum(total) 銷售合計

from 訂單表

group by convert(char(8),ordertime,112)

如果需要增加查詢條件,在from後加where 即可。

sql 查詢每個月的記錄數量

13樓:匿名使用者

那要看你入庫時間欄位是什麼型別,什麼格式,如果是date型別,要用group by left(入庫時間,7)分組

如果是datetime型別,要用group by convert(varchar(7),入庫時間,23)分組

如果是字元型,格式同date,那麼也用date的分組方式,如果格式僅為月份,

那麼只需要用本身分組即可group by 入庫時間

14樓:

select datepart(year,[入庫時間])*100+datepart(month,[入庫時間]),count(*)

from 表名

group by datepart(year,[入庫時間])*100+datepart(month,[入庫時間])

改下,是*100

15樓:匿名使用者

select left(convert(varchar(10), [入庫時間], 120), 7) as [月份], count(*) as [數量]

from [表名]

group by left(convert(varchar(10), [入庫時間], 120), 7)

16樓:

select count(*) from table where 入庫時間 between '月初' and ‘月末’

sql語句 統計表裡記錄的總和

17樓:匿名使用者

假設 表名為" 統計" 欄位名為"金額"

select sum(金額) from 統計

18樓:匿名使用者

select sum(列名) from 表名

VB內嵌SQL語句完成對access資料庫的查詢問題

adodc3.recordsource select from 庫存清單 where 庫存清單.商品編號 text4.text 這行 中的 去掉 adodc3.recordsource select from 庫存清單 where 庫存清單.商品編號 text4.text 提示from子句錯誤的話,...

求sql語句,求!!!SQL語句!

隨緣寫法你看是你要的不,實際上要是已經是1和0了 直接sum也行select a1,sum a2 sum a3 from a group by a1 既然已經是1和0了,那麼直接sum就可以了 select place,sum tdbz sum xdbz from table group by pl...

sql語句中,SQL語句中USE

三歲喝酒 use pubs 選擇 名字 pubs 的資料庫 select title id from sales where title id in 查詢欄位title id符合號內限定條件的表sales的 title id 列 select title id from titles where t...