jamespakorn / jamespakorn/hdc-sql
anc5p
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
``` sql
/------------ s_anc5 ------------/;
SET @prov_c := '14';
SET @id:= 'bd63b8d99f7054560fcf9c3b96f39c13';
SET @cat_id := '1ed90bc32310b503b7ca9b32af425ae5';
SET @b_year:='2017';
SET @start_d:=concat(@b_year-1,'1001');
SET @end_d:=concat(@b_year,'0930');
CREATE TABLE IF NOT EXISTS s_anc5(
id varchar(32) NOT NULL,
hospcode varchar(5) NOT NULL,
areacode varchar(8) NOT NULL,
flag_sent varchar(1) DEFAULT NULL,
date_com varchar(14) DEFAULT NULL,
b_year varchar(4) NOT NULL,
target int(7) DEFAULT 0,
result int(7) DEFAULT 0,
target1 int(7) DEFAULT 0,
result1 int(7) DEFAULT 0,
target2 int(7) DEFAULT 0,
result2 int(7) DEFAULT 0,
target3 int(7) DEFAULT 0,
result3 int(7) DEFAULT 0,
target4 int(7) DEFAULT 0,
result4 int(7) DEFAULT 0,
PRIMARY KEY (id,hospcode,areacode,b_year),
KEY (hospcode),
KEY (areacode),
KEY (b_year)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
DELETE FROM s_anc5 WHERE id=@id AND b_year=(@b_year+543);
INSERT IGNORE INTO s_anc5
(SELECT @id,p.hospcode,p.vhid
,@send,DATE_FORMAT(now(),'%Y%m%d%H%i') as d_com,@b_year+543
,COUNT(DISTINCT CONCAT(l.cid,'-',l.bdate)) target
,COUNT(DISTINCT IF(a.g1_ga <=12 AND a.g2_ga IN(16,17,18,19,20) AND a.g3_ga IN(24,25,26,27,28)
AND a.g4_ga IN(30,31,32,33,34) AND a.g5_ga IN(36,37,38,39,40)
, CONCAT(a.cid,'-',a.bdate),NULL)) result
,COUNT(DISTINCT IF(DATE_FORMAT(l.bdate,'%m') IN(10,11,12), CONCAT(l.cid,'-',l.bdate),NULL)) targetq1
,COUNT(DISTINCT IF(DATE_FORMAT(l.bdate,'%m') IN(10,11,12) AND a.g1_ga <=12 AND a.g2_ga IN(16,17,18,19,20)
AND a.g3_ga IN(24,25,26,27,28) AND a.g4_ga IN(30,31,32,33,34) AND a.g5_ga IN(36,37,38,39,40)
, CONCAT(a.cid,'-',a.bdate),NULL)) resultq1
,COUNT(DISTINCT IF(DATE_FORMAT(l.bdate,'%m') IN(1,2,3), CONCAT(l.cid,'-',l.bdate),NULL)) targetq2
,COUNT(DISTINCT IF(DATE_FORMAT(l.bdate,'%m') IN(1,2,3) AND a.g1_ga <=12 AND a.g2_ga IN(16,17,18,19,20)
AND a.g3_ga IN(24,25,26,27,28) AND a.g4_ga IN(30,31,32,33,34) AND a.g5_ga IN(36,37,38,39,40)
, CONCAT(a.cid,'-',a.bdate),NULL)) resultq2
,COUNT(DISTINCT IF(DATE_FORMAT(l.bdate,'%m') IN(4,5,6), CONCAT(l.cid,'-',l.bdate),NULL)) target3
,COUNT(DISTINCT IF(DATE_FORMAT(l.bdate,'%m') IN(4,5,6) AND a.g1_ga <=12 AND a.g2_ga IN(16,17,18,19,20)
AND a.g3_ga IN(24,25,26,27,28) AND a.g4_ga IN(30,31,32,33,34) AND a.g5_ga IN(36,37,38,39,40)
, CONCAT(a.cid,'-',a.bdate),NULL)) resultq3
,COUNT(DISTINCT IF(DATE_FORMAT(l.bdate,'%m') IN(7,8,9), CONCAT(l.cid,'-',l.bdate),NULL)) target4
,COUNT(DISTINCT IF(DATE_FORMAT(l.bdate,'%m') IN(7,8,9) AND a.g1_ga <=12 AND a.g2_ga IN(16,17,18,19,20)
AND a.g3_ga IN(24,25,26,27,28) AND a.g4_ga IN(30,31,32,33,34) AND a.g5_ga IN(36,37,38,39,40)
, CONCAT(a.cid,'-',a.bdate),NULL)) resultq4
FROM t_labor l
INNER JOIN t_person_cid p ON l.cid=p.cid
INNER JOIN chospital h ON p.hospcode=h.hoscode
LEFT JOIN t_person_anc a ON l.cid=a.cid AND l.bdate =a.bdate
WHERE l.BDATE BETWEEN @start_d AND @end_d AND l.BTYPE NOT IN(6)
AND p.typearea in(1,3) AND p.nation in(99) AND h.provcode in(@prov_c) AND p.discharge IN(9)
GROUP BY p.hospcode,p.vhid
);
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reviewing the SQL block in the issue, especially the s_anc5 table definition and the query joining t_labor, t_person_cid, chospital, and t_person_anc. No repository files, tests, or acceptance criteria are named, so first confirm where this report belongs and what output should be validated before considering the work done.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- sql
- Domain
- database
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100