jamespakorn / jamespakorn/hdc-sql

tmp_nutrition

Open
#10 2 comments 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,'1001');
SET @end_d:=concat(@b_year,'0930');
SET @date_3:=concat(@b_year-14,'1001');

DROP TABLE IF EXISTS tmp_nutrition;
CREATE TABLE tmp_nutrition (
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_service;
CREATE TABLE IF NOT EXISTS t_nutrition_service(
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,
quarter_m int(1) DEFAULT 0,
nutri1 int(1) DEFAULT 0,
nutri2 int(1) DEFAULT 0,
nutri3 int(1) DEFAULT 0,
PRIMARY KEY (hospcode,pid,quarter_m)
) ENGINE MyISAM DEFAULT CHARACTER SET=utf8;

INSERT IGNORE INTO t_nutrition_service (HOSPCODE,PID,CID,SEQ,DATE_SERV,WEIGHT,HEIGHT,HEADCIRCUM,FOOD,BOTTLE
,BIRTH,SEX,NATION,quarter_m)
(
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,1,
IF(DATE_FORMAT(n.DATE_SERV,'%m') BETWEEN 1 AND 3,2,
IF(DATE_FORMAT(n.DATE_SERV,'%m') BETWEEN 4 AND 6,3,
IF(DATE_FORMAT(n.DATE_SERV,'%m') BETWEEN 7 AND 9,4,0
)))) as quarter_m
FROM
tmp_nutrition 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 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_service 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 provides no filename, test, or requested change; start by reviewing the SQL entry point containing SET @prov_c and the tmp_nutrition and t_nutrition_service creation statements. Done cannot be determined until the intended behavior and validation criteria are specified.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.