Technology Get the latest on technology, electronics and software…

SQL Help

Thread Tools
 
Old 12-21-2009, 04:09 PM
  #1  
Keeping emos out of
Thread Starter
 
goose25's Avatar
 
Join Date: May 2004
Location: Colorado Springs
Posts: 6,811
Received 1 Like on 1 Post
Post SQL Help

Hello to all you SQL experts. Can one of you provide a bit of assistance with the following problem? I've searched my textbook and can't figure out the answer.

I need to create SQL Select statements that would produce running summary files for reports on the following:

Customer volume by month
CustomerID, Month, Total shipments, Total weight

Driver performance by month
Driver ID, Month, Number of manifests on time, Number of manifests delivered late.

Any assistance would be greatly appreciated.
Old 12-21-2009, 05:17 PM
  #2  
Team Owner
 
doopstr's Avatar
 
Join Date: Jan 2001
Location: Jersey
Age: 52
Posts: 25,430
Received 2,177 Likes on 1,194 Posts
select * from Whiskers where porn = "yes"
Old 12-21-2009, 05:54 PM
  #3  
Safety Car
 
Anachostic's Avatar
 
Join Date: Jul 2007
Posts: 4,845
Received 145 Likes on 90 Posts
Originally Posted by goose25
Hello to all you SQL experts. Can one of you provide a bit of assistance with the following problem? I've searched my textbook and can't figure out the answer.

I need to create SQL Select statements that would produce running summary files for reports on the following:

Customer volume by month
CustomerID, Month, Total shipments, Total weight

Driver performance by month
Driver ID, Month, Number of manifests on time, Number of manifests delivered late.

Any assistance would be greatly appreciated.
Do you mean running total? I don't see any columns in your examples that indicate running totals. Your columns look more like a GROUP BY CustomerID/DriverID, Month
Old 12-21-2009, 05:55 PM
  #4  
Safety Car
 
Anachostic's Avatar
 
Join Date: Jul 2007
Posts: 4,845
Received 145 Likes on 90 Posts
Originally Posted by doopstr
select * from Whiskers where porn = "yes"
Strings are identified with single quotes, so:

select * from Whiskers where porn = 'yes'
Old 12-21-2009, 06:08 PM
  #5  
Drifting
iTrader: (1)
 
rza49311's Avatar
 
Join Date: Feb 2006
Location: Southern VA
Age: 45
Posts: 3,072
Received 8 Likes on 6 Posts
Originally Posted by goose25
Hello to all you SQL experts. Can one of you provide a bit of assistance with the following problem? I've searched my textbook and can't figure out the answer.

I need to create SQL Select statements that would produce running summary files for reports on the following:

Customer volume by month
CustomerID, Month, Total shipments, Total weight

Driver performance by month
Driver ID, Month, Number of manifests on time, Number of manifests delivered late.

Any assistance would be greatly appreciated.
select Customerid, Month, sum(total shipments) as [Total Shipments], sum(total weight) as [Total Weight]
from table
group by Customerid, Month
order by Customerid, Month

Like so?
Old 12-21-2009, 06:39 PM
  #6  
Safety Car
 
Anachostic's Avatar
 
Join Date: Jul 2007
Posts: 4,845
Received 145 Likes on 90 Posts
Yes, that's what I'm thinking. Unless that's not what you want, then no.
Old 12-21-2009, 06:44 PM
  #7  
i want to ride my bicycle
iTrader: (1)
 
leftride's Avatar
 
Join Date: Sep 2003
Location: denver, co
Age: 43
Posts: 3,598
Received 21 Likes on 17 Posts
Originally Posted by rza49311
select Customerid, Month, sum(total shipments) as [Total Shipments], sum(total weight) as [Total Weight]
from table
group by Customerid, Month
order by Customerid, Month

Like so?
that or:

SELECT a.customerid, a.month, SUM(b.[total shipments]), SUM(b.[total weight])
FROM table a
JOIN table b
ON a.customerid = b.customerid
AND b.month <= a.month
GROUP BY a.customerid, a.month
ORDER BY 1,2

and the same general idea for the second one. Not sure the definitions of 'volume' or 'performance'
Old 12-22-2009, 09:03 PM
  #8  
Keeping emos out of
Thread Starter
 
goose25's Avatar
 
Join Date: May 2004
Location: Colorado Springs
Posts: 6,811
Received 1 Like on 1 Post
Originally Posted by leftride
that or:

SELECT a.customerid, a.month, SUM(b.[total shipments]), SUM(b.[total weight])
FROM table a
JOIN table b
ON a.customerid = b.customerid
AND b.month <= a.month
GROUP BY a.customerid, a.month
ORDER BY 1,2

and the same general idea for the second one. Not sure the definitions of 'volume' or 'performance'
Thanks a bunch man, that's exactly what i was looking for.
Old 12-22-2009, 09:25 PM
  #9  
Safety Car
 
Anachostic's Avatar
 
Join Date: Jul 2007
Posts: 4,845
Received 145 Likes on 90 Posts
Originally Posted by leftride
that or:

SELECT a.customerid, a.month, SUM(b.[total shipments]), SUM(b.[total weight])
FROM table a
JOIN table b
ON a.customerid = b.customerid
AND b.month <= a.month
GROUP BY a.customerid, a.month
ORDER BY 1,2

and the same general idea for the second one. Not sure the definitions of 'volume' or 'performance'
I just (re)read this solution. Joining the table to itself is a clever idea I hadn't thought of before. I was going to go with a subselect statement. I think I'm going to use that trick tomorrow. Thanks!
Old 12-22-2009, 09:28 PM
  #10  
Go Giants
 
Whiskers's Avatar
 
Join Date: Aug 2004
Location: PA
Age: 53
Posts: 69,916
Received 1,235 Likes on 824 Posts
Originally Posted by doopstr
select * from Whiskers where porn = "yes"
I divided by 0 and my penis exploded...
Old 12-22-2009, 09:56 PM
  #11  
i want to ride my bicycle
iTrader: (1)
 
leftride's Avatar
 
Join Date: Sep 2003
Location: denver, co
Age: 43
Posts: 3,598
Received 21 Likes on 17 Posts
glad that helped goose.

Love the SQL problems
Old 12-23-2009, 07:31 AM
  #12  
Drifting
iTrader: (1)
 
rza49311's Avatar
 
Join Date: Feb 2006
Location: Southern VA
Age: 45
Posts: 3,072
Received 8 Likes on 6 Posts
Originally Posted by Anachostic
I just (re)read this solution. Joining the table to itself is a clever idea I hadn't thought of before. I was going to go with a subselect statement. I think I'm going to use that trick tomorrow. Thanks!
yeah, we use that trick often, heck we have some queries where the same table is aliased 3 times
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
CHICKEN204
4G TL Photograph Gallery
16
02-08-2020 07:50 PM



Quick Reply: SQL Help



All times are GMT -5. The time now is 01:22 PM.