我必须在同一个表中选择两个project.project_dates
(一个用于开始,一个用于结束)我有两个字段project.start = true
并project.end = true
用于识别它
SQL 查询应该是什么样的?
我试过了:
SELECT
pz.cognome AS Cognome,
(select s.presa_in_carico_data from tbl_progetto s where s.is_progetto = 1 AND
s.cc_id_fk = cc.cc_id) as Start,
(select e.presa_in_carico_data from tbl_progetto e where e.is_dimissione = 1 AND
e.cc_id_fk = cc.cc_id) as End,
trf.trf_note AS "Tipo trattam.",
trf.trf_prezzou as Retta,
COUNT(tra.trt_id) AS "N.GG." /*<-- this is normal count from date range select from user(#) */
FROM
tbl_progetto p
JOIN tbl_cartellaclinica cc ON cc.cc_id = p.cc_id_fk
JOIN tbl_paziente pz ON pz.id = cc.pz_fk_id
JOIN tbl_distretti_sanitari di ON pz.distretto_appartenenza = di.dss_id
JOIN tbl_trattamenti tra ON p.pr_id = tra.pr_fk_id
WHERE
tra.trt_data BETWEEN '2012-08-01' AND '2012-08-31' AND
p.pr_faseriab_fk = 4
GROUP BY cc_id