sql >> Database teknologi >  >> RDS >> Mysql

mysql :flere SELECT-sætninger i 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. SailsJS - Hvordan specificerer man strengattributtlængde uden at få fejl ved oprettelse af post?

  2. Sådan læser du versionsnummer fra en databasefil i Android, som er placeret i aktiv mappe

  3. MySQL bitvise operationer, bloom filter

  4. Oracle-opdateringsforespørgsel for at opdatere poster i sekventiel rækkefølge