我有两个 SQL 查询,我想将它们合并到一个 SQL 查询中并显示在一张表上:
SELECT subname,subscribers as sub1 FROM reports_subreport where country ='1' and mp='0' and date ='2013-10-15' and NOT(subname LIKE '%Test%') order by site,subname
SELECT subscribers as sub2 FROM reports_subreport where country ='1' and mp='0' and date ='2013-10-08' and NOT(subname LIKE '%Test%') order by site,subname
应该在表格中显示类似这样的内容:
子名称 sub1 sub2
耳鼻喉科 222 202
你能帮我一下吗,因为我对 mysql 和 php 很陌生?
最佳答案
已经给出了一些更好、更专业的答案,但这个最好是了解正在发生的事情
SELECT subname,
(SELECT subscribers
FROM reports_subreport
WHERE country ='1' AND mp='0'
AND date ='2013-10-15'
AND NOT(subname LIKE '%Test%')
ORDER BY site,subname LIMIT 1) AS sub1,
(SELECT subscribers
FROM reports_subreport
WHERE country ='1' AND mp='0'
AND date ='2013-10-08'
AND NOT(subname LIKE '%Test%')
ORDER BY site,subname LIMIT 1) AS sub2,
FROM reports_subreport WHERE country ='1' AND mp='0'
AND date ='2013-10-15' AND NOT(subname LIKE '%Test%')
ORDER BY site,subname
关于php - mysql 从同一个表中选择一列两次,并且在 where 子句中使用不同的日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19374024/