手上有一個需求,查詢某個時間段,各個測站雨量總和,根據雨量值進行級別劃分,要關聯到對應的測站總數,對應的測站要關聯到對應的縣數。個人只能查到單一列欄位,多列欄位分組統計,望大牛指教!
sql code:
select rg, count(2) stcd
from (select t2.*,
(case
when y < 10 then
'0~10'
when y >= 10 and y <= 24.9 then
'10~24.9'
when y >= 25 and y <= 49.9 then
'25~49.9'
when y >= 50 and y <= 99.9 then
'50~99.9'
when y >= 100 and y <= 199.9 then
'100~199.9'
when y >= 200 and y <= 299.9 then
'200~299.9'
else
TO_CHAR(y)
end) rg
from (select t1.*, d.ADDVNM, d.ADDVCD, b.STNM
from (select r.stcd, sum(r.dyp) y
from ST_PPTN_R_LOC r
where r.dyp is not null
and r.tm BETWEEN
TO_DATE('2015-05-02 12:20:12',
'yyyy/mm/dd hh24:mi:ss') AND
TO_DATE('2018-05-02 12:20:12',
'yyyy/mm/dd hh24:mi:ss')
group by r.STCD) t1,
ST_STBPRP_B_LOC b,
ST_ADDVCD_D_LOC d
where t1.stcd = b.STCD
and b.ADDVCD = d.ADDVCD) t2) t3
group by rg;
效果圖:

資料表:

sql結果:

uj5u.com熱心網友回復:
這個效果?
with a as
(select '張三' name, '空洞' dept, 209 sal
from dual
union all
select '滅絕' name, '峨眉' dept, 253 sal
from dual
union all
select '李四' name, '空洞' dept, 271 sal
from dual
union all
select '令狐沖' name, '華山' dept, 932 sal
from dual
union all
select '岳靈珊' name, '華山' dept, 432 sal
from dual
union all
select '任盈盈' name, '華山' dept, 832 sal
from dual)
select count(distinct dept) 部門數量, count(distinct name) 人員數量, flag
from (select name,
dept,
case
when sal between 200 and 300 then
'200~300'
when sal between 301 and 500 then
'300~500'
else
'800以上'
end flag,
sal
from a)
group by flag
uj5u.com熱心網友回復:
能留個聯系方式,請教下嗎?uj5u.com熱心網友回復:
咋查詢的結果跟你不一樣呢?站數量和縣數量還是一樣??

資料表:
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/69690.html
標籤:開發
