首先让我先说我是mysql的新手。我正在从转储数据转换到excel并从那里使用voodoo,所以这种新语言可能令人困惑,但我正在处理简单的查询。
我无法找到答案的第一个问题是,我正在寻找可计费的医疗遭遇,然后将它们与在该时间段内看到的患者数量进行比较。 (编辑:这是我在这里遇到问题的“CASE WHEN声明”
可结算遭遇由唯一遭遇计算,可以将该遭遇的任意数量的可计费代码之一计为可计费。 (还有更多的代码,但我为空间而截断)
这就是我迄今为止所做的事情当然不起作用:
SELECT
CONCAT(`users`.`ulname`,', ',`users`.`ufname`) AS Provider
, YEAR(e.`date`) AS 'YEAR'
, LEFT(MONTHNAME(e.date), 3) AS 'MONTH'
, COUNT(DISTINCT e.`patientID`) AS Pts
, COUNT(DISTINCT e.`encounterID` CASE WHEN d.`value`
IN ('99213','99214','99212','99203','99202','90832','99393') THEN END AS
Bill_Encs
, COUNT(e.`status`) AS 'Vts_CHK'
, COUNT(e.`status`) - COUNT(DISTINCT e.`encounterID`)
AS No_Codes
FROM enc e
INNER JOIN `mobiledoc`.`users` ON `users`.`uid` = e.`ResourceId`
INNER JOIN `billingdata` billing ON billing.`EncounterId` =
e.`encounterID`
INNER JOIN items i ON i.`itemID` = billing.`itemID`
INNER JOIN `itemdetail` d ON d.`itemID` = i.`itemID`
WHERE e.`date` BETWEEN CAST('2017-10-26' AS DATE) AND CAST('2017-10-31' AS
DATE)
AND d.`propID` = 13
AND billing.`deleteFlag` = 0
AND i.`deleteFlag` = 0
AND e.status = "CHK"
AND e.`deleteFlag` = 0
AND e.`encType` = 1
AND e.`ClaimReq` = 1
AND `users`.`UserType` = 1
GROUP BY Provider ASC, YEAR(e.`date`) ,MONTH(e.`date`) ASC;
答案 0 :(得分:0)
如果所有其他方面都相同(正常),我认为你只想要条件聚合。
, COUNT(DISTINCT e.`encounterID` CASE WHEN d.`value`
IN ('99213','99214','99212','99203','99202','90832','99393') THEN END AS
Bill_Encs
变为
, COUNT(DISTINCT CASE WHEN d.`value`
IN ('99213','99214','99212','99203','99202','90832','99393') THEN e.`encounterID` END AS Bill_Encs