我有7桌,以獲得data.Below列出的表MySQL的一排用不同的頭銜
SELECT
visits.policy_id,persons.full_name,visits.person_id,visits.date,
(CASE WHEN test_types.name = 'Blood Glucose (Fasting)' THEN visit_test_entries.result ELSE " " END) AS BSL_F,
(CASE WHEN test_types.name = 'Blood Glucose (Post Prandial) 2 hrs' THEN visit_test_entries.result ELSE " " END) AS BSL_PP,
(CASE WHEN test_types.name = 'Triglycerides (Fasting)' THEN visit_test_entries.result ELSE " " END) AS TGL,
(CASE WHEN test_types.name = 'Low Density Lipoprotein (LDL)' THEN visit_test_entries.result ELSE " " END) AS LDL,
(CASE WHEN test_types.name = 'HDL (Fasting)' THEN visit_test_entries.result ELSE " " END) AS HDL,
(CASE WHEN test_types.name = 'Total Cholesterol (Fasting)' THEN visit_test_entries.result ELSE " " END) AS Total_Cholesterol
FROM
visits,provider_locations,providers,visit_test_entries,test_types,persons,households hh
WHERE
visits.provider_location_id=provider_locations.id
AND visits.provider_id=providers.id
AND visits.id=visit_test_entries.visit_id
AND visit_test_entries.test_type_id=test_types.id
AND visits.person_id=persons.id
AND persons.household_id=hh.id
AND visits.date >="2016-06-01"
AND visits.provider_location_id=1
AND visits.valid_state='valid'
- 訪問
- 提供商位置
- 提供商 與人不同的值的列
- visit_test_entries
- test_types
- pers附件
- 戶
現在,我得到的輸出喜歡這個
--------------------------------------------------------------------------|
policy_id| full_name|person_id|date |BSL_F|BSL_PP|TGL|LDL|HDL|Tot_Cho|
---------|----------|---------|----------|-----|------|---|---|---|-------|
AN00234 | Rajesh | 2309330 |2017-04-02|123 | | | | | |
---------|----------|---------|----------|-----|------|---|---|---|-------|
AN00234 | Rajesh | 2309330 |2017-04-02| |435 | | | | |
---------|----------|---------|----------|-----|------|---|---|---|-------|
AN00234 | Rajesh | 2309330 |2017-04-02| | |45 | | | |
---------|----------|---------|----------|-----|------|---|---|---|-------|
AN00234 | Rajesh | 2309330 |2017-04-02| | | |78 | | |
---------|----------|---------|----------|-----|------|---|---|---|-------|
AN00234 | Rajesh | 2309330 |2017-04-02| | | | |120| |
---------|----------|---------|----------|-----|------|---|---|---|-------|
AN00234 | Rajesh | 2309330 |2017-04-02| | | | | |170 |
--------------------------------------------------------------------------|
但我需要這樣的
--------------------------------------------------------------------------|
policy_id| full_name|person_id|date |BSL_F|BSL_PP|TGL|LDL|HDL|Tot_Cho|
---------|----------|---------|----------|-----|------|-------|---|-------|
AN00234 | Rajesh | 2309330 |2017-04-02|123 | 435 |45 |78 |120|170 |
--------------------------------------------------------------------------|
放MAX()。 – xQbert