範圍年齡的查詢很常用
select case when (to_char(sysdate, 'yyyy' )-to_char(t.csrq,'yyyy')) between 18 and 30 then '18-30歲'
when (to_char(sysdate, 'yyyy' )-to_char(t.csrq,'yyyy')) between 31 and 41 then '31-41歲'
when (to_char(sysdate, 'yyyy' )-to_char(t.csrq,'yyyy')) > 41 then '41歲以上' end as 年齡段,count(*)人數
from lds_employment_info t
group by case when (to_char(sysdate, 'yyyy' )-to_char(t.csrq,'yyyy')) between 18 and 30 then '18-30'
when (to_char(sysdate, 'yyyy' )-to_char(t.csrq,'yyyy')) between 31 and 41 then '31-41'
when (to_char(sysdate, 'yyyy' )-to_char(t.csrq,'yyyy')) > 41 then '41以上' end
order by 年齡段
//when右邊的括號意思是(當前系統的年份-乙個date欄位的年份)
//plsql 結果如下:
查詢人數最多的部門及各部門男女人數
首先是建表語句 spool employee.log prompt prompt creating table employee prompt prompt create table jcxt.employee id varchar2 20 name varchar2 20 varchar2 20 ...
sql查詢 範圍查詢(區間查詢)
1 範圍查詢 區間查詢 2 in 3 查詢年齡為18,28,38的人 select from student where age 18 or age 28 or age 38 4 select from student where age in 18,28,38 5 not in6 查詢年齡為18,...
SQL對取值範圍進行分組彙總
假設現在有這麼兩個表,要做關聯查詢,查詢出每個鄉鎮每個年齡段的driver有多少個,該怎麼寫sql語句?查詢出結果是這種的 那麼sql應該怎麼寫呢 sql server資料庫環境 select town name count case when nl between 1and 5then nl en...