我有一个大表,现在表按日期细分为几个
例如
原表
UserLoginTable
+---------+------------+---------+
| UserID | LoginTime | others |
+---------+------------+---------+
| 1 | 2013-03-12 | .... |
+---------+------------+---------+
| 2 | 2013-05-12 | .... |
+---------+------------+---------+
| 1 | 2013-06-12 | .... |
+---------+------------+---------+
| ... | ... | .... |
+---------+------------+---------+
现在表格是:
UserLoginTable_Date(yyyyMM)
用户登录表_201303
+---------+------------+---------+
| UserID | LoginTime | others |
+---------+------------+---------+
| 1 | 2013-03-12 | .... |
+---------+------------+---------+
用户登录表_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
...
所以我想知道如何通过一个 sql 显示这种格式
+--------------+
| UserInYear |
+--------------+
| 201303 | //here dose find User in 201304
+--------------+
| 201306 |
+--------------+
| .... |
+--------------+
最佳效率点。谢谢。