sql >> Database >  >> RDS >> Mysql

mysql:meerdere SELECT-instructies in Common Table Expression

WITH
cte AS ( SELECT n.name,
                e.value, 
                ROW_NUMBER() OVER (PARTITION BY e.value 
                                   ORDER BY {expression-1}) AS rn
         from entries e 
         LEFT JOIN nodes n on n.id=e.node_id 
         LEFT JOIN attribs a on a.id=e.attrib_id 
         WHERE  a.name = 'LOCATION' 
           AND e.value IN ('Wienerberg', 'Gruberstrasse')
           AND DATE(ts) = CURRENT_DATE
         ORDER BY {expression-2}
       ),
nums AS ( SELECT 1 rn UNION 
          SELECT 2 UNION 
          SELECT 3 UNION 
          SELECT 4 UNION 
          SELECT 5
        )
SELECT t1.name LNZ, t2.name WBG
FROM nums
LEFT JOIN cte t1 ON nums.rn = t1.rn
LEFT JOIN cte t2 ON nums.rn = t2.rn
WHERE t1.value = 'Gruberstrasse'
  AND t2.value = 'Wienerberg'
--  AND COALESCE(t1.name, t2.name)
ORDER BY nums.rn 




  1. Hoe u handmatig een waarde in de identiteitskolom in de SQL Server-tabel kunt invoegen - SQL Server / T-SQL-zelfstudie, deel 41

  2. Hoe te SELECTEREN * maar zonder Kolomnamen moeten uniek zijn in elke weergave

  3. mysqldump winkel null als leeg

  4. Hoe de nieuwste vier items per categorie SELECTEREN?