Title: MYSQL Case with inner join
Tags: mysql
Question: I have the following statement:
SELECT
Dag AS Dag,
CASE
Jaar
WHEN 2013
THEN Levering
END AS '2013',
CASE
Jaar
WHEN 2014
THEN Levering
END AS '2014'
tbl_Levering
INNER JOIN tbl_EParameter
ON (Maand = tbl_EParameter.ZMaand)
ORDER BY Dag
The output give two records for each day of that month. In the first record the value of 2013and in the second row the value of 2014. I want to have one record.
What do I wrong in the statement.
Comment: Use a `GROUP BY` clause.


Here is another answer: I do not understand what you are asking.
But note that CASE can not be used to change the column name.
Could show you expect to get?
What you want is this you?
SELECT
Jaar AS 'Year',
AS Dag Dag
tbl_Levering
INNER JOIN tbl_EParameter
ON (Maand = tbl_EParameter.ZMaand)
GROUP BY 1;

Here is another answer: this should do the trick use max with group by so that you will have one row per dag and result for 2013 ,2014 in two separate columns if you don't use max then group by results are indeterminate and any of row from same group will be picked in end results
SELECT
Dag AS Dag,
MAX(CASE
Jaar
WHEN 2013
THEN Levering
END) AS '2013',
MAX(CASE
Jaar
WHEN 2014
THEN Levering
END) AS '2014'
tbl_Levering
INNER JOIN tbl_EParameter
ON (Maand = tbl_EParameter.ZMaand)
GROUP BY Dag
ORDER BY Dag
Comment for this answer: With the MAX I get indeed one record, but only the record of the last day of the month and not the other days of the month.

Here is another answer: I like to add a picture but that is not allowed for me a this moment.
The table have the following fields
Jaar , Maand, Dag, Levering
So for every day in the month I have one record with the delivery in kHw for my solarpanels
In the query I want for month 6, value stored in tbl_EParameter.Zmaand the record from 2013 and 2014, like this
Dag 2013  2014
1    5     4,5
2    6,8   3,2
etc, etc

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 3, 'CommentCount': 1, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2014:00:07/25/14', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<mysql>', 'Title': 'MYSQL Case with inner join', 'ViewCount': 53, 'id': 24963509, 'user_AboutMe': '<p>MySql (MariaDb) on Synology,\nMS Access as front-end</p>\n', 'user_AccountId': 4801909.0, 'user_DisplayName': 'JanR', 'user_Reputation': 1.0, 'user_Views': 0.0, 'user_id': 3878309.0}}