自己写的一个复杂查询
每天都有很多数据,通过复杂查询统计每个月的数据
select *
from(
SELECT [BeginTime],[TimeLength],[Fee],[CallerNo],[CallerNoOld],[BoxNo] FROM [ssdfeedata].[dbo].[fee12120150101] union all
SELECT [BeginTime],[TimeLength],[Fee],[CallerNo],[CallerNoOld],[BoxNo] FROM [ssdfeedata].[dbo].[fee12120150102] union all
SELECT [BeginTime],[TimeLength],[Fee],[CallerNo],[CallerNoOld],[BoxNo] FROM [ssdfeedata].[dbo].[fee12120150103] union all
SELECT [BeginTime],[TimeLength],[Fee],[CallerNo],[CallerNoOld],[BoxNo] FROM [ssdfeedata].[dbo].[fee12120150104] union all
SELECT [BeginTime],[TimeLength],[Fee],[CallerNo],[CallerNoOld],[BoxNo] FROM [ssdfeedata].[dbo].[fee12120150105] union all
SELECT [BeginTime],[TimeLength],[Fee],[CallerNo],[CallerNoOld],[BoxNo] FROM [ssdfeedata].[dbo].[fee12120150106] union all
SELECT [BeginTime],[TimeLength],[Fee],[CallerNo],[CallerNoOld],[BoxNo] FROM [ssdfeedata].[dbo].[fee12120150107] union all
SELECT [BeginTime],[TimeLength],[Fee],[CallerNo],[CallerNoOld],[BoxNo] FROM [ssdfeedata].[dbo].[fee12120150108] union all
SELECT [BeginTime],[TimeLength],[Fee],[CallerNo],[CallerNoOld],[BoxNo] FROM [ssdfeedata].[dbo].[fee12120150109] union all
SELECT [BeginTime],[TimeLength],[Fee],[CallerNo],[CallerNoOld],[BoxNo] FROM [ssdfeedata].[dbo].[fee12120150110] union all
SELECT [BeginTime],[TimeLength],[Fee],[CallerNo],[CallerNoOld],[BoxNo] FROM [ssdfeedata].[dbo].[fee12120150111] union all
SELECT [BeginTime],[TimeLength],[Fee],[CallerNo],[CallerNoOld],[BoxNo] FROM [ssdfeedata].[dbo].[fee12120150112] union all
SELECT [BeginTime],[TimeLength],[Fee],[CallerNo],[CallerNoOld],[BoxNo] FROM [ssdfeedata].[dbo].[fee12120150113] union all
SELECT [BeginTime],[TimeLength],[Fee],[CallerNo],[CallerNoOld],[BoxNo] FROM [ssdfeedata].[dbo].[fee12120150114] union all
SELECT [BeginTime],[TimeLength],[Fee],[CallerNo],[CallerNoOld],[BoxNo] FROM [ssdfeedata].[dbo].[fee12120150115] union all
SELECT [BeginTime],[TimeLength],[Fee],[CallerNo],[CallerNoOld],[BoxNo] FROM [ssdfeedata].[dbo].[fee12120150116] union all
SELECT [BeginTime],[TimeLength],[Fee],[CallerNo],[CallerNoOld],[BoxNo] FROM [ssdfeedata].[dbo].[fee12120150117] union all
SELECT [BeginTime],[TimeLength],[Fee],[CallerNo],[CallerNoOld],[BoxNo] FROM [ssdfeedata].[dbo].[fee12120150118] union all
SELECT [BeginTime],[TimeLength],[Fee],[CallerNo],[CallerNoOld],[BoxNo] FROM [ssdfeedata].[dbo].[fee12120150119] union all
SELECT [BeginTime],[TimeLength],[Fee],[CallerNo],[CallerNoOld],[BoxNo] FROM [ssdfeedata].[dbo].[fee12120150120] union all
SELECT [BeginTime],[TimeLength],[Fee],[CallerNo],[CallerNoOld],[BoxNo] FROM [ssdfeedata].[dbo].[fee12120150121] union all
SELECT [BeginTime],[TimeLength],[Fee],[CallerNo],[CallerNoOld],[BoxNo] FROM [ssdfeedata].[dbo].[fee12120150122] union all
SELECT [BeginTime],[TimeLength],[Fee],[CallerNo],[CallerNoOld],[BoxNo] FROM [ssdfeedata].[dbo].[fee12120150123] union all
SELECT [BeginTime],[TimeLength],[Fee],[CallerNo],[CallerNoOld],[BoxNo] FROM [ssdfeedata].[dbo].[fee12120150124] union all
SELECT [BeginTime],[TimeLength],[Fee],[CallerNo],[CallerNoOld],[BoxNo] FROM [ssdfeedata].[dbo].[fee12120150125] union all
SELECT [BeginTime],[TimeLength],[Fee],[CallerNo],[CallerNoOld],[BoxNo] FROM [ssdfeedata].[dbo].[fee12120150126] union all
SELECT [BeginTime],[TimeLength],[Fee],[CallerNo],[CallerNoOld],[BoxNo] FROM [ssdfeedata].[dbo].[fee12120150127] union all
SELECT [BeginTime],[TimeLength],[Fee],[CallerNo],[CallerNoOld],[BoxNo] FROM [ssdfeedata].[dbo].[fee12120150128] union all
SELECT [BeginTime],[TimeLength],[Fee],[CallerNo],[CallerNoOld],[BoxNo] FROM [ssdfeedata].[dbo].[fee12120150129] union all
SELECT [BeginTime],[TimeLength],[Fee],[CallerNo],[CallerNoOld],[BoxNo] FROM [ssdfeedata].[dbo].[fee12120150130] union all
SELECT [BeginTime],[TimeLength],[Fee],[CallerNo],[CallerNoOld],[BoxNo] FROM [ssdfeedata].[dbo].[fee12120150131]
) a
where a.callerno = '1535'
order by begintime
/*group by a.callerno
order by LongTime desc*/