Jump to content

MSSQL group by help


synking

Recommended Posts

Hey guys. I asked this question in the php coding help as i was not sure where i needed to do it but got help

 

I need to do some math to the results for the table.  I need to have the all months entered group together and then have the columns K001, K002, and total multiplied by 22 to get a month total of used amount.

 

I have a table structure that looks like this.

 

Array (
    [Manufacturer] => SUPERIOR
    [Description] => S-0170 B BLEND
    [VOCContent] => 100
    [Disbursed] => 55
    [Recovered] => 0
    [Month] => October
    [K001] => 0.67
    [K002] => 1.83
    [usePerDay] => 2.5
    [TotalVocEmissions] => 17.45
    [TotalK001] => 4.68
    [TotalK002] => 12.77
    [Year] => 2001
)

 

so far i have tried this but i am not that fluent in sql statements beyond the very basic.

 

"Select
    Manufacturer,
    Description,
    VOCContent,
    Disbursed,
    Recovered,
    Month,
    K001,
    K002,
    UsePerDay,
    TotalVocEmissions,
    TotalK001,
    TotalK002
FROM 
    SolventUsage
Where
    Month > '$month'
and
    Year > '$year'
Group BY
    month, year";

That is just one i have tried.  But that gets an error about columns not being contained as aggregate or in the group by.

 

anyone able to point me in a direction to solve this

Link to comment
Share on other sites

From what I've read your overcomplicating things and confusing yourself.

 

Are you trying to multiply columns K001, K002, and total by 22? If so, why are you doing that when you need the total? Unless I've completely misinterpreted your problem.

Link to comment
Share on other sites

I am honestly not sure the best route to take... still trying to figure it out.

 

What i need to do is group them by month.  So all of the entries for the month of august are together.  Then I have a few fields that are not stored in the database that are based off of the total usage for that month.

 

So all of august usage grouped and then used to create a total for K001, K002, and the totalvocemission are created as separate fields

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.