SELECT symptom.sym_id, (SELECT COUNT(*) FROM treat_history) AS Count_treat,symptom.sym_name FROM symptom INNER JOIN treat_history ON symptom.sym_id=treat_history.sym_id GROUP BY symptom.sym_id,symptom.sym_name
SELECT symptom.sym_id, (SELECT COUNT(*) FROM treat_history) AS Count_treat,symptom.sym_name FROM symptom INNER JOIN treat_history ON symptom.sym_id=treat_history.sym_id GROUP BY symptom.sym_id,symptom.sym_name Where ... ชื่อโรคที่ต้องการแสดง หรือ Code ที่เรากำหนดไว้ครับ
SELECT
st.sym_id, st.sym_name,
(SELECT COUNT(*) FROM treat_history where sym_id = st.sym_id ) AS Count_treat
FROM symptom st
หรือ Code (SQL)
SELECT st.sym_id, st.sym_name, ct.Count_treat
FROM symptom st
innert join
(SELECT sym_id, COUNT(*) Count_treat FROM treat_history group by sym_id) ct
on ct.sym_id = st.sym_id