I have two queries. One yields the total number of records for a specific procedure type. The other yields the number of records for that specific procedure by the species
I am trying to figure out how I can take and get both the number of counts and the average number for each of the specific procedure types.
Query yielding total number by procedure type:
/* The following query will show the total number of studies by imaging area. */
SELECT
PlacerFld2 AS "Type of Procedure", Count(*) AS "Count of Procedures"
FROM
[order] o
WHERE
lastmodifieddate BETWEEN '2017-01-01 00:00:00' AND '2017-12-31 23:59:59'
AND SiteBridgeID = '1' /* Medical Imaging */
AND OrderStatusID <> '4'
AND placerfld2 IN ('CARD', 'CARM', 'CRFL', 'CT', 'I131', 'LACR', 'LAUS', 'NUCMED','OUTFM','PCCR','PETCT','PETR','PHMR','SACR','SAES','SAMR','SAUS','VRC','VRUS')
GROUP BY
PlacerFld2
ORDER BY
PlacerFld2 ASC
Example output:
CT 2056
SAMR 1800
SACR 3600
Query yielding total number of procedures by species
/* The following query will break down the number of studies by species */
SELECT PlacerFld2 AS "Type of Procedure", City AS Species, Count(*) AS "Count of Procedures"
FROM [order] o
LEFT JOIN Visit v
ON o.VisitID = v.VisitID
LEFT JOIN PatientInfo pif
ON v.PatientID = pif.PatientID
LEFT JOIN Patient p
ON pif.PatientID = p.PatientID
LEFT JOIN PersonalInfo perinfo
ON p.PersonalInfoID = perinfo.PersonalInfoID
WHERE o.lastmodifieddate between '2017-01-01 00:00:00' AND '2017-12-31 23:59:59'
AND SiteBridgeID = '1' /* Medical Imaging */
AND OrderStatusID <> '4'
AND placerfld2 IN ('CARD','CARM','CRFL','CT','I131','LACR','LAUS','NUCMED','OUTFM','PCCR','PETCT','PETR','PHMR','SACR','SAES','SAMR','SAUS','VRC','VRUS')
GROUP BY Placerfld2, CITY
ORDER BY placerfld2 ASC, CITY ASC
Example Table Output:
CT CANINE 1500
CT FELINE 556
SAMR CANINE 1000
SAMR FELINE 600
SAMR EQUINE 200
Desired Results:
CT CANINE 1500 72.9%
CT FELINE 556 27.1%
SAMR CANINE 1000 55.5%
SAMR FELINE 600 33.3%
SAMR EQUINE 200 11.1%