sql server - SQL statment, Sum the number of occurrences, Group them and Order them from highest to lowest according to the number of occurrences -



sql server - SQL statment, Sum the number of occurrences, Group them and Order them from highest to lowest according to the number of occurrences -

i having problem creating study pulling info database using sql-server. have 3 tables: incident, action , agency.

within incident table have attributes such

primary key (incident_id) , others (status , action_id).

in action table have

foreign keys (incident_id , agency_id) primary key (action_id).

in

agency table

i have

primary key (agency_id) , other attributes such (agency_name , agency_type).

i need sql statement groups according type, sums number of actions incident has , orders them highest lowest, status closed.

any help appreciated. time.

using mysql syntax, next should help along way:

select ag.agency_type, count(ac.action_id) incident inner bring together action ac on i.incident_id=ac.incident_id inner bring together agency ag on ac.agency_id=ag.agency_id i.status='closed' grouping ag.agency_type order count(ac.action_id) desc;

sql-server

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -