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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 [Resolved] Building a query

Author  Topic 

snufse
Constraint Violating Yak Guru

469 Posts

Posted - 2009-02-17 : 07:52:20
I have a sales table that contains following fields:
Period_Month, Period_Year, Amount and BOL (bill of lading).

I need to build a query that does a couple of things:

Gives me the record count by Period_Year and Period_Month
and also gives me the the total amount by Period_Year and Period_Month.

My question is: Do I have to build 2 separate queries? Thank you.

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-02-17 : 08:12:09
select count(*) as [count],sum(amount) as totalamount from urtable
group by Period_Month, Period_Year
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-02-17 : 08:15:10
For clarity

select Period_Month, Period_Year,count(*) as [count],sum(amount) as totalamount from urtable
group by Period_Month, Period_Year

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

snufse
Constraint Violating Yak Guru

469 Posts

Posted - 2009-02-17 : 09:54:43
Thank you guys, worked purrrfectly!
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-02-17 : 23:41:57
quote:
Originally posted by snufse

Thank you guys, worked purrrfectly!



welcome
Go to Top of Page
   

- Advertisement -