MYSQL - 显示包括空值在内的所有行

时间:2017-08-07 18:35:59

标签: mysql

我正在使用两个表。

ft_form_1
ID | facility_id |承认|放电|人口普查|待定| reporting_date | LAST_MODIFIED_DATE

ft_field_options
ID | option_value | option_name | option_order | LIST_ID

通过以下查询,我可以从今天所有设施中获取所有“提交”的列表,其中list_id等于1.如果发送重复提交,则仅显示最近提交的内容。

问题:此查询仅显示今天提交的设施列表及其后续数据。如何显示今天未提交的设施列表并显示空白或空值?

SELECT t1.facility_id, t2.option_name, t2.option_order, t1.admits, 
t1.reporting_date, t1.last_modified_date, t1.discharges, t1.census, 
t1.pending, DATE_FORMAT(t1.reporting_date,'%m/%d/%Y') AS nicedate
FROM ft_form_1 t1
LEFT JOIN ft_field_options t2
ON (t1.facility_id = t2.option_value AND t2.list_id = 1)
WHERE (DATE_FORMAT(t1.reporting_date,'%m/%d/%Y') = 
DATE_FORMAT(NOW(),'%m/%d/%Y')) AND (t1.last_modified_date=(
SELECT MAX(last_modified_date)
FROM ft_form_1
WHERE facility_id = t1.facility_id))
ORDER BY option_order ASC

1 个答案:

答案 0 :(得分:0)

你的问题是如此简单,只需按照你的选择,你可以通过测试找到你的答案,并在没有任何关于mysql的知识的情况下多次运行

SELECT t1.facility_id, t2.option_name, t2.option_order, t1.admits, 
t1.reporting_date, t1.last_modified_date, t1.discharges, t1.census, 
t1.pending, DATE_FORMAT(t1.reporting_date,'%m/%d/%Y') AS nicedate
FROM ft_form_1 t1
LEFT JOIN ft_field_options t2
ON (t1.facility_id = t2.option_value AND t2.list_id = 1)
WHERE (DATE_FORMAT(t1.reporting_date,'%m/%d/%Y') != 
DATE_FORMAT(NOW(),'%m/%d/%Y')) AND (t1.last_modified_date=(
SELECT MAX(last_modified_date) AND (t2.optaion_name IS NULL or t2.opation_name = "")
FROM ft_form_1
WHERE facility_id = t1.facility_id))
ORDER BY option_order ASC

我在你的代码中添加了一些东西,就在这里你运行它并自己添加你需要的东西