Technology Get the latest on technology, electronics and software…

SQL Help

Thread Tools
 
Old Dec 21, 2009 | 04:09 PM
  #1  
goose25's Avatar
Thread Starter
Keeping emos out of
 
Joined: May 2004
Posts: 6,811
Likes: 1
From: Colorado Springs
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.
Reply
Old Dec 21, 2009 | 05:17 PM
  #2  
doopstr's Avatar
Team Owner
20 Year Member
Liked
Loved
Community Favorite
 
Joined: Jan 2001
Posts: 25,967
Likes: 2,685
From: Jersey
select * from Whiskers where porn = "yes"
Reply
Old Dec 21, 2009 | 05:54 PM
  #3  
Anachostic's Avatar
Safety Car
 
Joined: Jul 2007
Posts: 4,845
Likes: 145
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
Reply
Old Dec 21, 2009 | 05:55 PM
  #4  
Anachostic's Avatar
Safety Car
 
Joined: Jul 2007
Posts: 4,845
Likes: 145
Originally Posted by doopstr
select * from Whiskers where porn = "yes"
Strings are identified with single quotes, so:

select * from Whiskers where porn = 'yes'
Reply
Old Dec 21, 2009 | 06:08 PM
  #5  
rza49311's Avatar
Drifting
iTrader: (1)
 
Joined: Feb 2006
Posts: 3,072
Likes: 8
From: Southern VA
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?
Reply
Old Dec 21, 2009 | 06:39 PM
  #6  
Anachostic's Avatar
Safety Car
 
Joined: Jul 2007
Posts: 4,845
Likes: 145
Yes, that's what I'm thinking. Unless that's not what you want, then no.
Reply
Old Dec 21, 2009 | 06:44 PM
  #7  
leftride's Avatar
i want to ride my bicycle
iTrader: (1)
 
Joined: Sep 2003
Posts: 3,598
Likes: 21
From: denver, co
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'
Reply
Old Dec 22, 2009 | 09:03 PM
  #8  
goose25's Avatar
Thread Starter
Keeping emos out of
 
Joined: May 2004
Posts: 6,811
Likes: 1
From: Colorado Springs
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.
Reply
Old Dec 22, 2009 | 09:25 PM
  #9  
Anachostic's Avatar
Safety Car
 
Joined: Jul 2007
Posts: 4,845
Likes: 145
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!
Reply
Old Dec 22, 2009 | 09:28 PM
  #10  
Whiskers's Avatar
Go Giants
20 Year Member
Liked
Loved
Community Favorite
 
Joined: Aug 2004
Posts: 70,003
Likes: 1,260
From: PA
Originally Posted by doopstr
select * from Whiskers where porn = "yes"
I divided by 0 and my penis exploded...
Reply
Old Dec 22, 2009 | 09:56 PM
  #11  
leftride's Avatar
i want to ride my bicycle
iTrader: (1)
 
Joined: Sep 2003
Posts: 3,598
Likes: 21
From: denver, co
glad that helped goose.

Love the SQL problems
Reply
Old Dec 23, 2009 | 07:31 AM
  #12  
rza49311's Avatar
Drifting
iTrader: (1)
 
Joined: Feb 2006
Posts: 3,072
Likes: 8
From: Southern VA
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
Reply
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
CHICKEN204
4G TL Photograph Gallery
16
Feb 8, 2020 07:50 PM




All times are GMT -5. The time now is 11:19 AM.