Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
k80sg
Starting Member
7 Posts |
Posted - 2011-11-18 : 02:06:39
|
| Hi, I have a TOP 1 query(Query2) below which I would like to join it to Query 1 but I can't seem to do something like this:"select Count(*), Avg(AmtSpent), TOP 1 (Outlet_Code)...."Please kindly advice. Thanks.Query 1:select Count(*), Avg(AmtSpent) from Transact Where CardNo In(Select CardNo from Card where MemberID = 'Mem003')Query 2:select TOP 1 (Outlet_Code) from Transact where CardNo In(Select CardNo from Card where MemberID = 'Mem003')group by Outlet_CodeOrder by count(Outlet_Code) desc |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-11-18 : 03:33:29
|
do you mean this?select top 1 t.Outlet_Code,count(1) over (),Avg(AmtSpent) over ()from Transact tinner join Card cON c.CardNo = t.CardNo where c.MemberID = 'Mem003'group by t.Outlet_Codeorder by count(*) desc ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|