統計sql整理

2021-09-02 16:41:20 字數 2450 閱讀 4561

專案統計sql記錄:

獲取不同誠信等級的企業數

1:首先獲取某個網格區域,某個企業型別所有的活動的企業數

3:排除誠信評定中同乙個企業在同乙個評定級別中多條記錄去最新的企業的評定等級

select ec.score_level,count(ec.score_level) as count

from g_enterprise_credit ec

inner join (

select enterprise_id,max(update_time) as update_time,score_level from g_enterprise_credit

group by

enterprise_id

) m on m.enterprise_id = ec.enterprise_id and m.update_time = ec.update_time and m.score_level =        ec.score_level

inner join g_enterprises as en on en.id = ec.enterprise_id

left join g_enterprise_type as et on et.id = ec.enterprise_type_id

left join g_system_netregion as sn on sn.id = en.net_range_id

where

ec.is_tmp_storage = 0

and ec.`status` = 2

and ec.enterprise_type_id like '0112%'

and en.net_range_id in (

'dd5fa7fa-80d4-cb29-c4d4-e0592efba8a8',

'e48d6b98-a834-e8fc-083e-809b006c6615'

and en.is_active = 1

and ec.enterprise_id not in (

select e.id from  g_administrative_penalty ap

inner join (

select max(penalty_time) as penalty_time,enterprise_id from

g_administrative_penalty group by enterprise_id

) m on m.penalty_time = ap.penalty_time and m.enterprise_id = ap.enterprise_id

inner join g_enterprises e on e.id = ap.enterprise_id

inner join g_enterprise_type et on et.id = ap.enterprise_type_id where

e.is_active = 1

and e.register_area_stan like '321081%'

and e.net_range_id in (

'dd5fa7fa-80d4-cb29-c4d4-e0592efba8a8',

'e48d6b98-a834-e8fc-083e-809b006c6615'

and ap.is_active = '1'

and (

ap.penalty_time >= 1420041600

and ap.penalty_time <= 1451491200

and ap.enterprise_type_id like '0112%'

and e.id in (

select

a.id

from

g_enterprises a

left join g_area_stan c on c.area_code = a.register_area_stan

left join g_system_netregion d on d.id = a.net_range_id

left join g_re_enterprises_types et on et.enterprise_id = a.id

where

1 = 1

and a.register_area_stan like '321081%'

and a.is_active = 1

and net_range_id in (

'dd5fa7fa-80d4-cb29-c4d4-e0592efba8a8',

'edb7f03b-994b-741d-8050-023ed8ed511b')

and enterprise_type_id like '0112%'

group by

a.id

order by

ap.penalty_time desc

group by

ec.score_level;

統計報表 sql統計語句

需要資料統計頁面,肯定需要匯出資料,於是,邊學邊寫,完成了一段sql 最早的版本是這樣的 分三條sql查出三種不同的狀態的記錄數 總記錄,未支付,已支付 select count as recordcount from t record where createtime 2019 01 01 00 ...

統計學整理

1 統計學是一門收集 整理和分析大量統計資料的方法科學,其目的是探索資料的內在數量規律性,從而科學地認識客觀事物 2 時間序列的描述性基本指標有兩類 一類是現象發展的水平指標 一類是現象發展的速度指標。時間序列中各指標的數值稱為發展水平 3 增長量是時間序列中的報告期水平與基期水平之差,用於描述現象...

SQL按月統計

做統計就要和時間打交道。一 當前年的月統計 select b.number as month sum a.a4012 shouru,sum a.a4011 feiyong,sum a.a4012 a4011 lirun from a040a001 a right join select number...