select elt(interval(c.money, 0, 1000, 2000, 3000, 4000, 5000), 'less 1000', '1000to2000', '2000to3000', '3000to4000','4000to5000') as level, count(c.id) as cnt from (select sum(a.money) as money,b.id from 表1 as a,表2 as b where a.uid = b.id group by b.id) as c group by elt(interval(c.money, 0, 1000, 2000, 3000, 4000, 5000), 'less 1000', '1000to2000', '2000to3000', '3000to4000','4000to5000')
select
sum(
case
when examination_score between 90 and 100
then 1 else 0
end) as 優秀,
sum(
case
when examination_score between 80 and 90
then 1 else 0
end) as 良好
from el_test_info
MySQL按區間分組查詢統計報表
表結構如下 列名中文名usertripid 自增id eventtime 記錄時間,資料格式 yyyy mm dd hh mm ss h小時時間 m分鐘時間 userid 使用者id 部分資料內容如下,正常情況下資料量在35w左右 查詢語句 select d.eventtime,h,d.m,elt ...
mysql區間查詢 MySQL區間分組查詢
假設a表為會員資訊表,需要統計男性會員年齡各階段的出現的人數 create table a id int 11 unsigned not null auto increment,name varchar 255 not null default comment 會員名稱 tinyint 1 unsi...
MySQL區間分組查詢
假設a表為會員資訊表,需要統計男性會員年齡各階段的出現的人數 create table a id int 11 unsigned not null auto increment,name varchar 255 not null default comment 會員名稱 tinyint 1 unsi...