Finished Aufgabe 4.7
This commit is contained in:
parent
c251ba0e83
commit
b20572877a
@ -90,8 +90,22 @@ Geben Sie eine SQL Anfrage an, die alle Produkte ausgibt, die eine bestimmte Anz
|
||||
-----------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
SELECT Produktname, GROUP_CONCAT(eZ.Anwendungsgrund), GROUP_CONCAT(E_Nummer),
|
||||
LENGTH(GROUP_CONCAT(E_Nummer)) - LENGTH(REPLACE(GROUP_CONCAT(E_Nummer), ',', '')) + 1 AS 'Anzahl Zusatzstoffe'
|
||||
SELECT Produktname,
|
||||
IFNULL( # wenn feld NULL, Keine Emulgatoren
|
||||
REPLACE( # wenn feld zero, Keine Emulgatoren
|
||||
REPLACE( # wenn feld zwei, Zwei Emulgatoren
|
||||
REPLACE( # wenn feld eins, Ein Emulgator
|
||||
IF( # wenn feld größer als zwei, Mehr Emulgatoren, ansonsten setze den gleichen wert wieder ins feld
|
||||
LENGTH(GROUP_CONCAT(eZ.Anwendungsgrund)) - LENGTH(REPLACE(GROUP_CONCAT(eZ.Anwendungsgrund), 'E', ''))
|
||||
> 2, 'Mehr Emulgatoren',
|
||||
LENGTH(GROUP_CONCAT(eZ.Anwendungsgrund)) - LENGTH(REPLACE(GROUP_CONCAT(eZ.Anwendungsgrund), 'E', '')))
|
||||
, 1, 'Ein Emulgator')
|
||||
, 2, 'Zwei Emulgatoren')
|
||||
, 0, 'Keine Emulgatoren')
|
||||
, 'Keine Emulgatoren')
|
||||
AS Emgulagtoren,
|
||||
GROUP_CONCAT(eZ.Anwendungsgrund) AS 'Anwendungsgrund'
|
||||
FROM Produkt
|
||||
JOIN enthaeltZusatzstoff eZ on Produkt.ProduktID = eZ.ProduktID
|
||||
GROUP BY Produktname
|
||||
LEFT JOIN enthaeltZusatzstoff eZ on Produkt.ProduktID = eZ.ProduktID
|
||||
GROUP BY Produktname
|
||||
ORDER BY LENGTH(GROUP_CONCAT(eZ.Anwendungsgrund)) - LENGTH(REPLACE(GROUP_CONCAT(eZ.Anwendungsgrund), 'E', ''))
|
Loading…
Reference in New Issue
Block a user