sql - how to make mysql sub query -
i have big table,now table subdivided several date
e.g.
the original table
userlogintable +---------+------------+---------+ | userid | logintime | others | +---------+------------+---------+ | 1 | 2013-03-12 | .... | +---------+------------+---------+ | 2 | 2013-05-12 | .... | +---------+------------+---------+ | 1 | 2013-06-12 | .... | +---------+------------+---------+ | ... | ... | .... | +---------+------------+---------+
now table is:
userlogintable_date(yyyymm)
userlogintable_201303
+---------+------------+---------+ | userid | logintime | others | +---------+------------+---------+ | 1 | 2013-03-12 | .... | +---------+------------+---------+
userlogintable_201304
+---------+------------+---------+ | userid | logintime | others | //this table not have userid=1 +---------+------------+---------+ | 2 | 2013-04-01 | .... | +---------+------------+---------+
i used
select count(*) userlogintable_201307 userid=1 select count(*) userlogintable_201306 userid=1 ...
so want kown how show format 1 sql
+--------------+ | userinyear | +--------------+ | 201303 | //here dose find user in 201304 +--------------+ | 201306 | +--------------+ | .... | +--------------+
the best efficiency point. thanks.
try use union all
below
select count(*) userinyear userlogintable_201307 userid=1 union select count(*) userlogintable_201306 userid=1
note: union all
not eliminate duplicates. if don't want duplicates have use union
insetad.
Comments
Post a Comment