pivot requery SQLITE
(1) By anonymous on 2020-04-12 12:04:34 [source]
This query is OK:
Select substr(Tbl_Session.Date, 1 , 4) AS Date, sum(Case WHEN Tbl_Session.Type = 'type' THEN Tbl_Pois.Quantite end) as [TYPE 1], sum(Case WHEN Tbl_Session.Type = 'type1' THEN Tbl_Pois.Quantite end) as [TYPE 2] FROM (Tbl_Pois INNER JOIN Tbl_Session ON Tbl_Pois.Session_ID = Tbl_Session.ID_Session) WHERE Tbl_Pois.Resultat = 'dig'
But this work when we know "Case WHEN Tbl_Session.Type = 'type'"
Now we don't know how much and what clause "Case WHEN Tbl_Session.Type = ????"
How to do?
sorry my english is bad
(2) By Igor Tandetnik (itandetnik) on 2020-04-12 14:03:18 in reply to 1 [link] [source]
If you are asking how to write a SELECT statement that produces a different number of columns depending on the contents of the database, then you cannot - SQL doesn't work this way. The number and names of columns are determined by the query structure alone; only the number of rows depends on the data.
(3) By anonymous on 2020-04-13 07:11:52 in reply to 1 [link] [source]
So I didn’t take the lead, I kept the idea of the basic query in the 1st post, because even if it means creating variables in the query, I have as much program them directly according to a basic request which defines me all the CASE WHEN and it's good.