SQL Query Help

Discussion in 'OT Technology' started by Peyomp, Aug 3, 2006.

  1. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    So I was doing some computations in perl, and its on alot of data and I realized that i should be doing it in SQL.

    I have a table that contains hourly entries for 308 machines. I need to sum the values of one field for all machines of each type, and then return that value for each hour. I need to do this for all times between two datetime values.

    Is this hard?
     
  2. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    SELECT SUM(grossSales) FROM hourly WHERE datetime = ? AND vendor=?

    Only I don't want to run a seperate query for each hour... I want to do it all at once for many datetimes within a range.
     
  3. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    SELECT vendor, SUM(grossSales) as "Total sales" FROM hourly GROUP BY vendor;
     
  4. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    SELECT vendor, SUM(grossSales) as "Total sales" FROM hourly GROUP BY vendor WHERE datetime <= ? and datetime > ?;
     
  5. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    SELECT vendor, SUM(grossSales) as "Total sales" FROM hourly WHERE datetime >= 2006010108 and datetime < 2006010110 GROUP BY vendor;

    Closer...
     
  6. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    SELECT vendor, SUM(grossSales) as "Total sales" FROM hourly WHERE datetime >= 2006010108 and datetime < 2006010112 GROUP BY vendor, datetime;

    Answered me own question. Man, is that alot easier than doing it in perl!
     
  7. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    Wow, wrong forum. It is on a MacBook Pro though!
     

Share This Page