sql語句分組查詢前10條資料,sql如何實現分組並select出每組前10個

2021-10-05 03:03:19 字數 2810 閱讀 9830

1樓:匿名使用者

class classid classnameproduct classid proname numselect top 10 c.classid ,c.classname,sum(p.

num) from class c,product p where p.classid=c.classid group by c.

classid order by sum(p.num) desc

有的不能用top。,不同資料庫軟體查詢好像有細微的差別。

2樓:旅谷之

select sum(a.num) as cnum, min(b.classname) as clei,min(b.classid) as cid

from class b, product awhere b.classid = a.classidgroup by a.classid

order by cnum desc

如果要前 10,加top 10在select 後。

3樓:匿名使用者

select top 10 b.classid,b.classname,sum(a.num) as num

from product a,分類表 b

where a.classid=b.classidorder by num desc

4樓:匿名使用者

select top 10 * from (select t2.classname,sum(t1.num) as num .

t1.id from product t1, class t2 where t1.id=t2.

classid) t1 group by t1.num desc

5樓:

select b.classname,sum(a.num) as num

from product a left join class bwhere a.classid=b.classidorder by num desc

6樓:匿名使用者

你想按分類(classid)進行數量統計嗎

sql如何實現分組並select出每組前10個

7樓:匿名使用者

select m, n

from (

select row_number () over (partition by m order by n desc) rn,--以m分組,分組內以n倒序排列求每組中各自的序號

m, n

from table

where ...

) wwhere w.rn <=10;序號小於10order by m, n desc

sql資料庫怎麼實現分組並取每組的前1條語句,按日期排序?

8樓:果樹上的小黑貓

select * from

(select row_number() over(partition by '分組' order by '日期') as rownum -- 排序並分組

, * -- 所需顯抄示的欄位from 表

) as t

where t.rownum = 1

對每組的資料按日期排序並加上行號

取出時只取行號為1,也就是第一條資料。

9樓:匿名使用者

select top 1 * from 表 group by 分組條件 order by 日期

mysql怎麼查詢前10條資料?

10樓:匿名使用者

mysql沒有select top的語法,你得用用limit

select * from 表名 limit m,n;

從m開始,取n條

11樓:匿名使用者

select * from 你的表名 order by 你的欄位 limit 10select * from 你的表名 order by 你的欄位 limit 10select * from 你的表名 order by 你的欄位 limit 10select * from 你的表名 order by 你的欄位 limit 10select * from 你的表名 order by 你的欄位 limit 10select * from 你的表名 order by 你的欄位 limit 10select * from 你的表名 order by 你的欄位 limit 10select * from 你的表名 order by 你的欄位 limit 10select * from 你的表名 order by 你的欄位 limit 10select * from 你的表名 order by 你的欄位 limit 10select * from 你的表名 order by 你的欄位 limit 10select * from 你的表名 order by 你的欄位 limit 10select * from 你的表名 order by 你的欄位 limit 10select * from 你的表名 order by 你的欄位 limit 10

MySql怎麼查詢前10條資料mysql如何查詢各年的前10條記錄

mysql沒有select top的語法,你得用用limit select from 表名 limit m,n 從m開始,取n條 select from 你的表名 order by 你的欄位 limit 10select from 你的表名 order by 你的欄位 limit 10select ...

SQL查詢資料語句問題,SQL查詢資料語句問題

取n到m行 1.select top m from tablename where id not in select top n id from tablename order by id asc desc 2.select top m into 臨時表 或表變數 from tablename or...

sql查詢指定記錄的條數,sql語句查詢表內資料條數?

sql 使用 count可以統計指定記錄的條數 結合group by 可以統計不同分類的條目數 例子 id name 1 xk 2 kl 3 xk 統計name xk 的條數 select count number from table where name xk 結果number2 關注 upda...