问题描述
- tx_plans
- provider_ids
- 提供者
- ng_rest_prod
- 保险
- invis_ortho_codes
- thirds_implants
- next_visit
SELECT
b.patient_id,LIST(a.service_code,',' ORDER BY a.service_code) AS tx_plans,b.provider_id AS provider_ids,(d.last_name + ',' + d.first_name) AS providers,'' AS ng_rest_prod,NULL AS insurance,'' AS invis_ortho_codes,'' AS thirds_implants,NULL AS next_visit
FROM
transactions_header a
INNER JOIN transactions_detail b
ON a.tran_num = b.tran_num
INNER JOIN
(
SELECT
SUBSTRING(row_value,CHARINDEX('_',row_value)) AS tran_num,SUBSTRING(row_value,row_value)+1,LENGTH(row_value)) AS eod_date
FROM sa_split_list('914561_2020-08-03,914562_2020-08-03,914563_2020-08-03,914564_2020-08-03,914565_2020-08-03')
) c
ON a.tran_num = c.tran_num
INNER JOIN provider d
ON b.provider_id = d.provider_id
WHERE 1 = 1
AND a.impacts = 'P'
AND eod_date BETWEEN DATEFORMAT('2020-08-24 00:00:00','YYYY-MM-01') AND '2020-08-24 00:00:00'
GROUP BY b.patient_id,b.provider_id,providers
- patient_id
- 病人姓名
- 年龄
SELECT
b.patient_id,' + d.first_name) AS patient_name,FLOOR(DATEDIFF(DAY,d.birth_date,TODAY(*))/365) AS age
FROM
transactions_header a
INNER JOIN transactions_detail b
ON a.tran_num = b.tran_num
INNER JOIN
(
SELECT
SUBSTRING(row_value,914565_2020-08-03')
) c
ON a.tran_num = c.tran_num
INNER JOIN patient d
ON b.patient_id = d.patient_id
WHERE a.impacts = 'P'
AND eod_date BETWEEN DATEFORMAT('2020-08-24 00:00:00','YYYY-MM-01') AND '2020-08-24 00:00:00'
AND d.first_visit_date BETWEEN DATEFORMAT('2020-08-24 00:00:00','YYYY-mm-01') AND '2020-08-24 00:00:00'
AND a.tran_date = d.first_visit_date
GROUP BY b.patient_id,patient_name,d.birth_date.
它返回Invalid expression near 'b.provider_id = d.provider_id'
这是我实现的代码
SELECT
b.patient_id,b.patient_name AS patient_name,b.age AS age,LIST(@R_404_6422@TINCT(a.tx_plans)) AS tx_plans,LIST(
@R_404_6422@TINCT(
CASE
WHEN a.provider_ids IS NOT NULL
THEN a.provider_ids
ELSE ''
END
)
) AS provider_ids,LIST(
@R_404_6422@TINCT(
CASE
WHEN a.providers IS NOT NULL
THEN a.providers
ELSE ''
END
)
) AS providers,SUM(ng_rest_prod) AS ng_rest_prod,LIST(a.insurance,' ORDER BY a.insurance) AS insurance,LIST(@R_404_6422@TINCT(a.invis_ortho_codes)) AS invis_ortho_codes,LIST(@R_404_6422@TINCT(a.thirds_implants)) AS thirds_implants,LIST(a.next_visit) AS next_visit
FROM
(
SELECT
b.patient_id,providers
) AS a
RIGHT JOIN
(
SELECT
b.patient_id,'YYYY-MM-01') AND '2020-08-24 00:00:00'
AND d.first_visit_date BETWEEN DATEFORMAT('2020-08-24 00:00:00','YYYY-mm-01') AND '2020-08-24 00:00:00'
AND a.tran_date = d.first_visit_date
GROUP BY b.patient_id,d.birth_date
) b
ON a.patient_id = b.patient_id
GROUP BY b.patient_id,age
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)