GrantU
GrantU

Reputation: 6555

Mysql SUM and group by no working

I have just started a new question to make this a bit more clear.

I have just migrated from MS SQL to MySQL this query worked in MS SQL

This is rstCombinedChartData

enter image description here

Then the result which should have 2 column 'yes' and 'no' with values for some reason on mysql I'm getting just one and itemcolumn false.

enter image description here

As you can see for some reason it's adding up all the results giving 551 where it should be like this:

Yes x 
No x

Why?

This is the SQL Query:

SELECT
    itemColumn
    ,SUM(valueColumn) AS valueColumn
    ,label
    FROM
    rstCombinedChartData
        GROUP BY
        label
        ,itemColumn
        ORDER BY
         label DESC
    ,itemColumn DESC

Upvotes: 0

Views: 120

Answers (1)

Parixit
Parixit

Reputation: 3855

Plase try:


SELECT itemColumn, SUM(CAST(valueColumn AS SIGNED)), label FROM rstCombinedChartData GROUP BY label, itemColumn ORDER BY label DESC, itemColumn DESC

Upvotes: 1

Related Questions