Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 15th, 2008, 12:54 AM
Authorized User
 
Join Date: May 2008
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default Can I in SQL group by week & sum the values (i.e.

Hi,

If I have a table with a DATE and VALUE column, is it possible to write a SQL statement to produce the following output?

Week Starting Sum(Values in that week)
2/1/08 123 [i.e. summed the values of multiple records for which the date was in this week]
9/1/08 34
16/1/08 34
.
.
.


 
Old May 15th, 2008, 07:35 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

HI there.. can you post some of your data and the result you expect from that data?? that will be more helpful than just see the result...

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old May 16th, 2008, 07:25 AM
Authorized User
 
Join Date: May 2008
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I actually need an output of the following.

Output 1 Required - Total deposits per week per bank account
=================
Week_Starting, Sum(Value)Bank1, Sum(Value)Bank2, etc etc
23-Feb, 23, 34, 45...
1-Mar, 23, 454, 4534 ...
.
.

Output 2 Required - Bank Account Names (to match order of columns from Output 1)
=================
Bank A
Bank asdf
Bank BBB
.
.
For background I then need to pass to a graphing program arrays of the following which I will do in code once I have the SQL results from the DB:
* An array of Graph X-axis labels ==> From output 2
* Arrays of Y-axis values (one array per line to plot) ==> From output 1

Questions:
[1] What is the SQL for Output 1?
[2] How can I create SQL for Output 2 to ensure the order aligns
[3] Tricky one - How can I ensure I do get all week commencing dates even if there isn't an entry in the data for that week? Also for a week if one bank account doesn't have any entries I still want it to be populated with 0.



Thanks






Similar Threads
Thread Thread Starter Forum Replies Last Post
sum group values based on cell criteria darkdestroyer Excel VBA 1 January 9th, 2008 09:13 PM
Sum a column at the group level? srussell705 SharePoint Development 0 October 3rd, 2007 08:40 AM
SUM and GROUP BY in vba wdepreter Excel VBA 3 February 5th, 2007 06:11 AM
Group by , Sub Group by and Sum mateenmohd SQL Server 2000 1 March 29th, 2005 09:51 AM
GROUP BY Avg and Sum pinkandthebrain SQL Server 2000 3 July 14th, 2003 09:20 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.