我有一个大的表,现在该表被细分为几个日期如何使mysql子查询
例如,
原始表
UserLoginTable
+---------+------------+---------+
| UserID | LoginTime | others |
+---------+------------+---------+
| 1 | 2013-03-12 | .... |
+---------+------------+---------+
| 2 | 2013-05-12 | .... |
+---------+------------+---------+
| 1 | 2013-06-12 | .... |
+---------+------------+---------+
| ... | ... | .... |
+---------+------------+---------+
现在的表是:
UserLoginTable_Date(yyyyMM)
UserLoginTable_201303
+---------+------------+---------+
| UserID | LoginTime | others |
+---------+------------+---------+
| 1 | 2013-03-12 | .... |
+---------+------------+---------+
UserLoginTable_201304
+---------+------------+---------+
| UserID | LoginTime | others | //this table is not have UserID=1
+---------+------------+---------+
| 2 | 2013-04-01 | .... |
+---------+------------+---------+
我曾经
select count(*) from UserLoginTable_201307 where UserID=1
select count(*) from UserLoginTable_201306 where UserID=1
...
所以我想Kown如何通过一个SQL
+--------------+
| UserInYear |
+--------------+
| 201303 | //here dose find User in 201304
+--------------+
| 201306 |
+--------------+
| .... |
+--------------+
的最佳效率点,以示对这种格式。谢谢。
谢谢,你快速 – zt9788
我很抱歉,我也想知道,如何显示结果是UserInYear(不计数),只是日期(201307或201306 ...)如果计数> 0 – zt9788
尝试添加一些东西像''有'count(distinct date)> 0'在'where'子句下方 – Parado