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
 General SQL Server Forums
 New to SQL Server Programming
 Help needed with aggregate function

Author  Topic 

Sandor
Starting Member

2 Posts

Posted - 2012-08-22 : 16:07:00
Hello,

Would someone please provide assistance in completing a SQL query?

I run a small business and use a SQL database to record all transactions made by my clients.
This database contains the client name, transaction date and transaction amount.
I would like to see the clients that have spend more than £ 100 within the past 7 days.

I composed the query below with aggregate function. The query returns the client and the sum of all transactions
made in the past seven days. So far so good, but I only want to see clients who have spend more than 100.
What code do I have to add?

thanks and regards,
Sandor

------------------
Select

client,
Sum (transaction.amount)

from CUSTOMER DATABASE

where trans_dt>=today(*)-7

Group by client

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-22 : 16:10:54
[code]
Select

client,
Sum (transaction.amount)

from CUSTOMER DATABASE

where trans_dt>=today(*)-7

Group by client
having Sum (transaction.amount)>100
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Sandor
Starting Member

2 Posts

Posted - 2012-08-22 : 16:21:02
Hello visakh16,

Thanks so much for your quick reply.

I will use this code tomorrow

king regards,
Sandor
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-22 : 18:00:02
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -