Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««12

"Total Revenue Per Day" SQL Query Format Expand / Collapse
Author
Message
Posted Wednesday, April 24, 2013 3:22 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 3:31 PM
Points: 11,949, Visits: 10,982
DKN2101 (4/24/2013)
Syntax error.

If i do:

SELECT MAX(Revenue_Spend) AS "Largest Amount Spent" FROM MaxCents

I get the max amount spent, but I can't figure out how to get it to display the userID as well.


There is no need to aggregate the data. We already did that with the CTE. Which row do you want from the CTE?


_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1446245
Posted Thursday, April 25, 2013 2:09 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 3:31 PM
Points: 11,949, Visits: 10,982
Do you still need help with this?

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1446709
Posted Friday, April 26, 2013 12:47 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, April 26, 2013 3:46 AM
Points: 2, Visits: 2
can you explain it to me more details again?? I really confusing with this~





Gejala Kanker, Cara Membuat Kue, Cerita Anak
Post #1446812
Posted Friday, April 26, 2013 7:17 AM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 6:33 PM
Points: 22,475, Visits: 30,157
DKN2101 (4/24/2013)
Syntax error.

If i do:

SELECT MAX(Revenue_Spend) AS "Largest Amount Spent" FROM MaxCents

I get the max amount spent, but I can't figure out how to get it to display the userID as well.


How about this?


with MaxCents (UserID, Revenue_Spend) as
(
select
UserID,
SUM(Cents) TotalCents
from
DollarTransactions
where
createdDate >= '2012-12-01'
and createdDate < '2013-01-01'
group by
UserID
)
select top (1)
UserID,
TotalCents
from
MaxCents
order by
TotalCents desc;





Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #1446973
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse