create Table ##Sales (Agent Varchar(5) Null, DateNo int Null, Amount Money Null, Present char(1) Default 'N')
Select * from ##Sales
insert into ##Sales (Agent, DateNo, Amount, Present)
Select 'A', 2, 5000, 'Y' Union All
Select 'B', 3, 4000, 'Y' Union All
Select 'C', 4, 2000, 'N' Union All
Select 'D', 3, 10000, 'Y' Union All
Select 'E', 5, 5000, 'N' Union All
Select 'B', 4, 5000, 'N'
Please give Group by Query for Answer Should be :
Agent DateNo totalAmount PresentDays
A 1 5000.00 1
B 2 9000.00 1
C 1 2000.00 1
D 1 10000.00 1
E 1 5000.00 1
Select Agent, COUNT(DateNo) DateNo, SUM(Amount) Amount, count(Present) Present
from ##Sales
Group by Agent
Above query give output total Present Days but I want Total Amount according Agent and total Present Days


Khrizz49 reputationPosted Jul 20, 2015, 3:40 AM EDT
Khan Abrar AhmedRank #778 · 3K reputationPosted Jul 15, 2015, 11:56 PM EDT
from @Sales
where present='Y'
Group by Agent,Present
order by agent
ajeet verma21 reputationPosted Jul 16, 2015, 12:43 AM EDT
Raja TRank #685 · 3.5K reputationPosted Jul 16, 2015, 1:32 AM EDT
Suyambu Kesavan9 reputationPosted Jul 21, 2015, 4:12 AM EDT
ajeet verma21 reputationPosted Jul 21, 2015, 10:07 PM EDT