Given a SQL table
Transactions
ID INT
COMPANY_ID INT
STATUS INT
where STATUS IN (0,1)
indicates a free transaction and STATUS IN (2,3)
indicates a billable transaction, what simple (I hope) ANSI SQL statement will show me, per COMPANY_ID
, the number of billable transactions, non-billable transactions, and their ratio?
A conceptual prod in the right direction is fine if not a specific statement. My first attempts are to self-join on the table with WHERE
clauses for the two status groups, but I m stuck at how to get a column representing each distinct count so that I can compute the ratio.
This is conceptually very similar to summarize-aggregated-data but I m not sure how to extend that question to this one.