mysql在where子句中从同一表中选择两次具有不同日期的列 [英] mysql Select one column twice from the same table with different dates in the where clause
本文介绍了mysql在where子句中从同一表中选择两次具有不同日期的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个SQL查询,我想将它们合并到一个SQL查询中并显示在一张表上:
I have two sql queries which i want to combine in one SQL Query and display on one table:
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
应该在表格中显示类似这样的内容:
Should Display something Like This in a table:
子名称 sub1 sub2
ENT 222202
ENT 222 202
因为我是mysql和php的新手,所以请您在这里帮助我吗?
Could you please help me out here because iam new to mysql and php?
推荐答案
已经给出了一些更好的专业答案,但这是最好的理解方法
There are some better and professional answers already been given, but this one is best to understand what is going around
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
这篇关于mysql在where子句中从同一表中选择两次具有不同日期的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文