Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Group the application within the following time frames

$
0
0

UserName|     Time Frame|     No of Applications
Daniel          |  Week to date| 3
Daniel             |  Month to date| 10
Daniel| Year to date|400

Please help me get the above format, below is my statement and output.

select j.UserName, i.App_Date as "Time Frame", count(*) as "Num. of Applications" 
from tblApplication as i, tblUsers as j 
where i.User_ID = j.User_ID
group by j.UserName, i.App_Date
union
select distinct a.UserName, b.App_Date, count(b.User_ID) 
from tblUsers as a left join tblApplication as b on a.User_ID = b.User_ID 
where b.User_ID is null
group by a.UserName, b.App_Date

UserNameTime FrameNum. of Applications
Daniel 3
Daniel12/31/2012 12:00:00 AM1
Daniel1/1/2013 12:00:00 AM1
Daniel2/17/2013 10:37:15 AM1
Daniel2/18/2013 10:37:15 AM1
Daniel2/19/2013 10:37:15 AM1
Daniel2/20/2013 10:37:15 AM1
Daniel2/21/2013 10:37:15 AM1
Daniel2/22/2013 10:37:15 AM1



Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>