Can someone help me with SQL?

General

Can someone help me with SQL?

I have a table that I am trying to get a calculation out of.  Tbl_Source_Data is the name and the columns that will factor in are:

 

  • Ship_Date
  • Due_Date
  • Shipped_Volume

What I am trying to do is get a service level calculation for shipped volume that was shipped on or before the Due_Date.  I would have no problem in Excel but this is so different.  It would be Shipped_Volume, that was shipped on or before the due_date, divided by the sum of shipped_volume.

 

Thanks for any help that you can provide

 

 

  • SQL
  • Teradata

Accepted Solutions
Junior Contributor

Re: Can someone help me with SQL?

You need conditional aggregation

  100  
   * sum(case when Ship_Date <= Due_Date then Shipped_Volume else 0 end) -- shipped on or before the due_date
   / sum(Shipped_Volume)
1 ACCEPTED SOLUTION
2 REPLIES
Junior Contributor

Re: Can someone help me with SQL?

You need conditional aggregation

  100  
   * sum(case when Ship_Date <= Due_Date then Shipped_Volume else 0 end) -- shipped on or before the due_date
   / sum(Shipped_Volume)

Re: Can someone help me with SQL?

Thanks, that worked perfectly!