sql中,count的用法,關於SQL中count的用法

2022-03-11 17:58:10 字數 6560 閱讀 4387

1樓:滑鐵盧的拿破崙

count

返回集合中專案的數量(具體數目取決於集合)。

語法維度

dimensions.count

返回多維資料集中的維度數,其中包括 [measures] 維度。

級別«dimension»|«hierarchy».levels.count

返回維度或層次結構中的級別數,包括 [all] 級別(如果適用)。

集合 - 語法 1

count(«set»[, excludeempty | includeempty])

返回集合中的單元數。該語法允許分別使用 excludeempty 或 includeempty 標誌來排除或包含空單元。

集合 - 語法 2

«set».count

返回集合中的單元數,其中包括空單元。

元組«tuple».count

返回元組中的維度數。

說明 預設狀態下計算空的單元數。預設情況下,ole db 中可比較的 count 函式不包含空單元。

註釋若要從集合計數中排除空單元,請使用可選的 excludeempty 關鍵字。

示例如果 time 包含級別 year 和 month,year 的成員是 1994 和 1995,那麼下面的示例返回 24:

集合 - 示例 1

count()

集合 - 示例 2

time.month.members.count

sql中max和count如何混合使用

2樓:匿名使用者

我在sql server 2005中試了一下這樣是可以的。首先是建立一個試圖。然後通過檢視再來篩選如下:

select * from commodityinfo;

create view com_cou as select count (c.commodityname) as cou from commodityinfo c group by c.shopid;

select max(cou) from com_cou ;

3樓:傳說中的鷹王

先分組取出count值, 再將count值倒序排列,取第一個值就是最大的

select top 1 * from(

select count(cno) a from 表group by 欄位

) border by a desc

4樓:餘香淡淡

哈這個sql可以滿足你所需要的功能:

select max(expr1) as expr2from (select count(*) as expr1from 表

group by cno) derivedtbl

5樓:

select qty,max(qty),count(qty)

from table_name

group by qty

6樓:匿名使用者

select max(c) from (select count(cno) as c from table group by cno)a group by c

7樓:石亮東

select cno,max(num) from (select cno,count(*) as num from tablename

group by cno)

8樓:匿名使用者

那是你寫的不對 你的思路是對的

剛回答了個差不多的問題 你借鑑一下吧;

裡面用到了子查詢 你一定要學會這種方法

9樓:匿名使用者

這種問題應該去itpub或者csdn問...

求教sql count語句用法

10樓:唔製

1、2、3樓的不懂就別亂說,4樓漏了別名,而且不需要排序select id,count(id) countfrom test

group by id

11樓:天堂鳥地獄火

select id, count(*) from t group by id order by id

12樓:

例如:查詢學生總人數

select count(*)

from student;

13樓:匿名使用者

1、全部計數:select count(0) from

2、條件計數:select count(0) from where =

3、分組計數:select , , count(0) from group by ,

14樓:匿名使用者

計算行數

select count(0) from table

15樓:匿名使用者

select id as id, count(*) as [count] from 表名 group by id;

16樓:

select id ,count(*) from table group by id

sql 查詢使用count函式一個方法

17樓:

select 欄位a,

count(case when (條件) then 表1.欄位b end) as c

from 表1 inner join 表2 on 表1.欄位=表2.欄位

可以用case加條件。

18樓:匿名使用者

簡單select * from(select 欄位a,count(表1.欄位b) as c from 表1 inner join 表2 on 表1.欄位=表2.欄位)

as x where x.c 加條件

19樓:

select 欄位a,count(表1.欄位b) as c from 表1 inner join 表2 on 表1.欄位=表2.欄位 where ...

在資料庫中怎樣運用count 語句?急求準確答案!

20樓:匿名使用者

1.查詢表有多少條記錄

select count(*) from table;

2.查詢表中符合條件的記錄數

select count(*) from table where id > 100;

3.查詢每個分組的記錄數

select name, count(*) as count from table group by name;

關於sql中count的用法

21樓:肖思邱俊豪

用sum更好點,如

(一)select

a.單位名稱,sum(case

when

b.時間》='2007-04-01'

andb.時間<'2007-07-01'

then

1else

0end)

as[2007二季度],sum(case

when

b.時間》='2007-10-01'

andb.時間<'2008-01-01'

then

1else

0end)

as[2007四季度]

from表一a

left

join表二b

ona.單位名稱=b.單位名稱

group

bya.單位名稱

(二)select

a.單位名稱,sum(case

when

b.時間》='2007-04-01'

andb.時間<'2007-07-01'

andb.類別='e'

then

1else

0end)

as[2007二季度],sum(case

when

b.時間》='2007-10-01'

andb.時間<'2008-01-01'

andb.類別='e'

then

1else

0end)

as[2007四季度]

from表一a

left

join表二b

ona.單位名稱=b.單位名稱

group

bya.單位名稱

22樓:匿名使用者

好像看明白了

select b,(select count(*) from x where a='b'),c,(select count(*) from x where a='c'),d,(select count(*) from x where a='d'),a,count(*) from x

你是不是要這種效果???

嗯,很浪費資源的說

最好分開取值

23樓:匿名使用者

select count(a) as 個數,a from 表 group by a

24樓:沈進煜

你a到底是一個欄位還是一張表啊

select count() from a.....

25樓:

select count(a) from x where a=b

select count(a) from x where a=c

select count(a) from x where a=c

sql語句count怎麼使用?

26樓:匿名使用者

過多繁瑣的sql影響**質量,及維護成本,以下為兩種小技巧處理方式,僅供參考。

第一種,用case ---when---方法

select id

,sum(case when type in (1,2) then [count] else 0 end) as sum1

,sum(case when type in (3) then [count] else 0 end) as sum2

,sum(case when type in (4,5) then [count] else 0 end) as sum3

from 表名

group by id

第二種,if 判斷

select   sum( goods_amount ) as money,

count( * ) as num,

count(if(pay_status=1,true,null)) as success,

count(if(pay_status=2,true,null)) as fall

from `tab_order_info`

where user_id = 11

27樓:匿名使用者

下面的幾條語句完成向a表插入10000條c=1,d=2,e=3的記錄:

declare @c int,@d int,@e int,@count int

select @c=1,@d=2,@e=3,@count=10000while @count>0

begin

insert into a表(c,d,e) values(@c,@d,@e)

set @count=@count-1end

關於sql函式count(*)的使用!

28樓:匿名使用者

是這樣嗎:

select sum(case when a=b then 1 else 0 end) 相同數

from table

29樓:匿名使用者

select sum(case when(c=2) then 1 else 0 end) count_c,sum(case when(d=2) then 1 else 0 end) count_d from 表 where a='a' and b='c'

這樣得到的count_c和count_d就是統計出來的c和d列的值。

sql語句中count和count的區別

30樓:教育仁昌

sql語句中count和count沒有區別。表示返回匹配指定條件的行數。

sql count() 語法:

1、sql count(column_name) 函式返回指定列的值的數目(null 不計入),如:select count(column_name) from table_name。

2、sql count(*) 函式返回表中的記錄數,如:select count(*) from table_name。

3、sql count(distinct column_name) 函式返回指定列的不同值的數目,如:select count(distinct column_name) from table_name。

sql中and和or的用法,請指導,謝謝

這是邏輯運算子優先次序沒交代清楚所導致的。按照提問中的 篩選邏輯,系統會檢索出 喝奶時間 為 早 且 訂奶類別 為 250ml巴士氏鮮奶 的記錄,或者 訂奶類別 為 500ml巴氏鮮奶 的記錄。第一個是雙條件篩選,第二個是單條件篩選,只要是500ml巴氏鮮奶,不管它是早或晚,只要是500毫升的就能被...

Sql語句的TOP用法,sql查詢語句 top n的用法

select top 1 from table select top 1 2 from table 取前3行資料 區別就是 裡面可以是個表示式 沒有區別個人的習慣 在sqlserver2000中top後只可以跟常數,在2005後可以跟變數了 也許唯一的區別就是top expression 括號中可以...

在sql中 insert into 中能插入select 語

在sql中,insert into語句中可以插入select語句。insert into select語句用於複製表資料,將select語句選擇的內容通過insert語句插入到表中,可以是同一個表,也可以是兩個不同的表。示例如下 結果如下 拓展資料 sql insert into 語句 insert...