我写了这个代码,它有以下结果,现在我想总结一下联合后得到的两行的结果。 任何想法我怎么能这样做(我的意思是我需要在这个新的“桌子”上另一个选择)。 任何帮助表示赞赏
SELECT Date_format(`creation`, '%Y-%m-%d') AS short_date,
Sum(`param7`) AS time_spent_in_sessions,
Count(*) AS nb_of_sessions
FROM `f_colony_ios_play_resume_pn__20120823`
WHERE `id` IN ( '22965', '22966' )
UNION
SELECT Date_format(`creation`, '%Y-%m-%d') AS short_date,
Sum(`param8`) AS time_spent_in_sessions,
Count(*) AS nb_of_sessions
FROM `f_colony_ios_play_resume_pn__20120823`
WHERE `id` IN ( '22970', '22971' )
-----------------------------
result:
short_date time_spent_in_sessions nb_of_sessions
2012-08-23 7 2
2012-08-23 10 1
答案 0 :(得分:4)
SELECT short_date, SUM(time_spent_in_sessions), SUM(nb_of_sessions)
FROM (both your queries here) AS subquerytable
我认为这是要走的路......