Home > database > SQL column data packet statistics
SQL column data packet statistics
Time:09-23
Hand there is a demand, query time, each station precipitation combined, according to the rainfall value divides the level to link to the corresponding total station, the corresponding station to associate to the corresponding number of county, personal refer only to a single column, column group statistics, more hope Daniel give advice or comments!
SQL code: Select the rg, the count (2) the STCD The from (select t2. *, (case The when y & lt; 10 then '0 ~ 10' The when y & gt;=10 and y & lt;=24.9 then '10 ~ 24.9' The when y & gt;=25 and y & lt;=49.9 then '25 ~ 49.9' The when y & gt;=50 and y & lt;=99.9 then '50 ~ 99.9' The when y & gt;=100 and y & lt;=199.9 then '100 ~ 199.9' The when y & gt;=200 and y & lt;=299.9 then '200 ~ 299.9' The else TO_CHAR (y) End) rg The from (select t1. *, da DDVNM, da DDVCD, b.S TNM The from (select r.s TCD, sum (r.d yp) y The from ST_PPTN_R_LOC r Where r.d yp is not null And r.t m 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.S TCD) t1, ST_STBPRP_B_LOC b, ST_ADDVCD_D_LOC d Where a t1. STCD=b.S TCD Da DDVCD) t2 t3 and b.A DDVCD= Group by rg.
Effect:
Data sheets:
SQL results:
CodePudding user response:
This effect?
With a as (select 'zhang' name, 'empty' dept, sal 209 The from dual Union all Select 'destroy' name, 'emei' dept, sal 253 The from dual Union all Select 'bill' name, 'empty' dept, sal 271 The from dual Union all Select 'no' name, 'hua' dept, sal 932 The from dual Union all Select 'lenient' name, 'hua' dept, sal 432 The from dual Union all Select 'ren ying ying' name, 'hua' dept, sal 832 The from dual) Select count (distinct dept) department number, count (distinct name), flag The from (select name, Dept, Case The when sal between 200 and 300 then '200-300 The when sal between 301 and 500 then '300-500 The else 'more than 800' End flag, Sal From a) Group by flag