SQL 不同類別的資料總數

2025-05-03 20:30:07 字數 3158 閱讀 9085

1樓:匿名使用者

今天做程式時,需要選取新聞表中各種類別的新聞個一條放在乙個容器裡面。

以前都都按照類別選取幾條或者所有的記錄,並不是每個類別的記錄都選一條的,突然遇到,我還一下子,沒有了想法,試了幾個都不行,原本以為distinct可以做到,不過還是不行。

兩個表,乙個news表,乙個新山羨聞的類別class表 ,news中的幾個關鍵欄位為id,article,classid

class中的幾個關逗虛拍鍵欄位譽如為id,name

二、解決辦法:

我試了幾個不行後,重新翻閱了上學期剛剛學過的資料庫,最後還這真找到了答案,需要級聯查詢。

select * from news where id in (select min(id) as id from news group by classid order classid desc

這個語句記得以前是用過的,可就是健忘啊。

2樓:匿名使用者

select count( from 資訊陵族肆表尺轎穗寬 as t2 inner join 類別表 as t1 on = group by

sql語句統計不同類別總數

3樓:網友

select 期數,身份,count(*)from tablename

group by 期數,身份。

sql 統計一張表中每種型別的記錄數量

4樓:網友

通過以下語句可以實現:

select ,count(*)from news a group by ;

sql 分組統計 同欄位不同型別資料分別統計

5樓:網友

這個意思?

select sum(case when name1='1' then money else 0 end) name1,sum(case when name1='2' then money else 0 end) name2,sum(case when name1 in('1','2') then money else 0 end) money

from test1

不過你給的那結果不對吧?

sql,統計問題,統計某欄位總數和符合某條件的數量

6樓:我也愛

select 名稱。

count(*)as 總數量。

count(case when 型別。

a' then 型別 else null end) as 型別為a的數。

from 表名內。

group by 名稱容。

7樓:匿名使用者

你可以試下:select 名稱,count(*)as 總數量,sum(case when 型別='a' then 1 else 0 end) as 型別為a的數量 from 表。

8樓:匿名使用者

select 名稱,count(*)總數量抄 into newtable from 表名 group by 名稱。

select count(*)型別。

襲為baia的數。

du into newtable2 from 表名 where 型別='a' group by 名稱select distinct(名稱),總數量,型別為a的數 from newtable,newtable2 乙個查詢zhi好像很難實現 所以用dao了兩個。

sql中對列中每個資料進行統計個數

9樓:

語句:select 課程,count(課程) 個數,max(成績) 最好成績 from 表。

group by 課程。

怎樣用一句sql,統計表中不同狀態的行的個數?

10樓:網友

select 系統名稱,sum(case when 故障狀態='已處理' then 1 else 0 end) as 已處理個數,sum(case when 故障狀態='未處理' then 1 else 0 end) as 未處理個數,count(*)as 總個數。

from 表名。

group by 系統名稱。

11樓:範青鋒

select 系統名稱,count(if(故障狀態='已處理',1,null)) 已處理個數,count(if(故障狀態='未處理',1,null)) 未處理個數,count(*)總個數。

from 表名。

group by 系統名稱;

求sql查詢語句,表的列資料按照條件不同輸出為不同的列,並統計個數。

12樓:網友

select distinct(單位),count(單位) as 型別。

數量,sum(case when 型別=1 then 1 else 0 end) as 型別為1 ,sum(case when 型別=2 then 1 else 0 end) as 型別為2,sum(case when 型別=3 then 1 else 0 end) as 型別為3

from sh1

group by 單位。

已測試,結果:

a2110b3111

c1010也祝福您專身體健康,多金多福 ,快屬採納,哈哈!

13樓:網友

select 單位。

zhi,sum(case 型別。

dao when '1' then 1 else 0 end) as 型別為。

版1,sum(case 型別 when '2' then 1 else 0 end) as 型別為2,sum(case 型別 when '3' then 1 else 0 end) as 型別為3

from 表權a group by 單位。

sql 中怎樣統計在一列中統計不同種類的書籍的數量

14樓:網友

select booktype as 書種歲舉模寬類,count(booktype) as 數量乎碼碧。

from books

group by booktype

sql語句查詢類別下所有子類sql語句查詢類別下所有子類

假如表名是 tablea select from tablea b where id between 2 and 6union all select from tablea a where exists select from tablea b where b.id between 2 and 6a...

劃掉不同類的詞語,劃去不同類的詞語

1 黯然 2 暢所欲言 第一個劃掉第四格。第二個劃掉第三個。劃去不同類的詞語 1.文學 其他都是文學題材的一種 2.跳水 其他都是田竟專案 3.鉛球 其他都是集體專案 懸賞分 0 離問題結束還有 14 天 23 小時1.詩歌 散文 戲劇 2.跳遠 跳高 標槍 鐵餅 3.棒球 籃球 足球 排球 1.詩...

根據每組單詞的類別,在橫線上寫出同類別的單詞

1.cake 2.teacher 3.shirt 4.cinema 5.elephant 6.write 答案不唯一 小學英語從a到的z單詞表 去 兒童 學習網 看看吧 單詞帶有讀音的!很標準 b汗 樓主,你還不如買本英語字典呢 寫出20個食物的英語的單詞寫上中文 你好 自 食物類 1.noodle...