1 分类统计
SELECT grade_protection_level AS type , count ( grade_protection_level) AS count
FROM ` vital_7jvebmrryff3_asset`
WHERE ( field_group = '应用信息' )
AND ( asset_life_cycle = '正式' )
AND ( status = 1 )
GROUP BY grade_protection_level
ORDER BY count ( grade_protection_level) DESC
func ( * dAnalyse) FindCount ( orgIds [ ] any) ( [ ] model. Analyse[ int ] , error ) {
res := [ ] model. Analyse[ int ] { }
err := AppsWhere ( ) . Select ( "grade_protection_level as type, count(grade_protection_level) as count" ) .
In ( "organization_id" , orgIds) .
GroupBy ( "grade_protection_level" ) .
OrderBy ( "count(grade_protection_level) desc" ) .
Find ( & res)
return res, err
}
2 多表联查
func ( * dAnalyse) FindTotalOrderDesc ( orgNames [ ] string ) ( [ ] model. Analyse[ int ] , error ) {
res := [ ] model. Analyse[ int ] { }
err := AppsWhere ( ) . Select ( "name as org, count(grade_protection_status) as count" ) .
Join ( "INNER" , "vital_7jvebmrryff3_organization" , "vital_7jvebmrryff3_asset.organization_id = vital_7jvebmrryff3_organization.id" ) .
In ( "name" , orgNames) .
Where ( "grade_protection_status = '未定级'" ) .
GroupBy ( "name" ) .
OrderBy ( "count(grade_protection_status) desc" ) . Find ( & res)
return res, err
}