jamespakorn / jamespakorn/hdc-sql

tmp_nutrition614

Open
#13 1 comment 0 reactions 0 assignees View on GitHub
คำสั่ง sql
Dominant language
No language data
Stars
0
Forks
0
PR merge metrics
No merged PRs in 30d

Description

```sql
SET @prov_c := '14';
SET @b_year:='2017';
SET @start_d:=concat(@b_year-1,'0101');
SET @end_d:=concat(@b_year,'1231');
SET @date_3:=concat(@b_year-14,'1001');

DROP TABLE IF EXISTS tmp_nutrition614;
CREATE TABLE tmp_nutrition614 (
error_code varchar(255) DEFAULT NULL,
KEY (cid),
KEY (hospcode,pid),
KEY (food,childdevelop)
) ENGINE=MyISAM AS(
SELECT
t.HOSPCODE,t.PID,t.SEQ,t.DATE_SERV,t.NUTRITIONPLACE,t.WEIGHT,t.HEIGHT,t.HEADCIRCUM,t.CHILDDEVELOP,t.FOOD,t.BOTTLE,t.PROVIDER,t.D_UPDATE,pe.cid,null as error_code
FROM
nutrition t LEFT JOIN person pe ON t.HOSPCODE=pe.HOSPCODE AND t.pid=pe.pid
WHERE
t.date_serv BETWEEN @start_d AND @end_d
);

DROP TABLE IF EXISTS t_nutrition_service614;
CREATE TABLE IF NOT EXISTS t_nutrition_service614(
hospcode VARCHAR(5) NOT NULL,
pid VARCHAR(15) NOT NULL,
cid VARCHAR(13) NOT NULL,
seq VARCHAR(16) NOT NULL,
date_serv date,
weight decimal(5,1) NOT NULL,
height int(3) NOT NULL,
HEADCIRCUM int(3) DEFAULT NULL,
FOOD varchar(1) DEFAULT NULL,
BOTTLE varchar(1) DEFAULT NULL,
BIRTH date,
SEX varchar(1) NOT NULL,
NATION varchar(3) DEFAULT NULL,
term int(1) DEFAULT 0,
nutri1 int(1) DEFAULT 0,
nutri2 int(1) DEFAULT 0,
nutri3 int(1) DEFAULT 0,
PRIMARY KEY (hospcode,pid,term)
) ENGINE MyISAM DEFAULT CHARACTER SET=utf8;

INSERT IGNORE INTO t_nutrition_service614 (HOSPCODE,PID,CID,SEQ,DATE_SERV,WEIGHT,HEIGHT,HEADCIRCUM,FOOD,BOTTLE
,BIRTH,SEX,NATION,term)
(
SELECT n.HOSPCODE,n.PID,p.cid,n.SEQ,n.DATE_SERV,n.WEIGHT,n.HEIGHT,n.HEADCIRCUM,FOOD,BOTTLE
,p.BIRTH,p.SEX,p.NATION, IF(DATE_FORMAT(n.DATE_SERV,'%m') BETWEEN 10 AND 12,2,
IF(DATE_FORMAT(n.DATE_SERV,'%m') BETWEEN 5 AND 7,1,0
)) as term
FROM
tmp_nutrition614 n INNER JOIN person p ON n.HOSPCODE=p.HOSPCODE AND n.PID=p.PID
WHERE WEIGHT BETWEEN 0.1 AND 300 AND HEIGHT BETWEEN 40 AND 250
AND TIMESTAMPDIFF(YEAR,p.birth,n.DATE_SERV) BETWEEN 6 AND 14
AND n.DATE_SERV >= p.birth
AND n.DATE_SERV BETWEEN @start_d AND @end_d
AND p.NATION in(99)
ORDER BY n.HOSPCODE ASC ,n.PID ASC ,n.DATE_SERV DESC
);

UPDATE t_nutrition_service614 SET nutri1=nutri_cal(TIMESTAMPDIFF(month,birth,date_serv),sex,1,height,weight)
,nutri2=nutri_cal(TIMESTAMPDIFF(month,birth,date_serv),sex,2,height,weight)
,nutri3=nutri_cal(TIMESTAMPDIFF(month,birth,date_serv),sex,3,height,weight);

Contributor guide

No contributing guide indexed for this repository

Research direction

The issue contains only a SQL script for tmp_nutrition614 and t_nutrition_service614, using the nutrition and person tables and nutri_cal function. Start by locating the related schema and SQL conventions, then clarify the intended change and expected result; the issue has no completion criteria or named test.

Written by the indexing model from the issue text.

Assessment

Tech stack
sql
Domain
databases
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.