sql >> Database >  >> RDS >> PostgreSQL

SQL:subquery heeft te veel kolommen

Je projecteert drie kolommen in uw subquery, maar een enkele één . vergelijken van hen in de IN clausule. Selecteer alleen de gewenste kolom (r1.king ) voor de IN in de subquery:

SELECT kingdom.king, dinasty.birth, dinasty.death
FROM kingdom, dinasty
WHERE kingdom.king = dinasty.name AND kingdom.king NOT IN
(
    SELECT DISTINCT R1.king
    FROM
    (
        SELECT DISTINCT R1.king, D1.birth, D1.death
        FROM kingdom AS R1, dinasty AS D1, dinasty AS D2
        WHERE R1.king=D1.name
    ) AS R1, 
    (
        SELECT DISTINCT R1.king, D1.birth, D1.death
        FROM kingdom AS R1, dinasty AS D1, dinasty AS D2
        WHERE R1.king=D1.name
    ) AS R2
    WHERE R1.death-R1.birth < R2.death-R2.birth
);


  1. ORA-12519 TNS:geen geschikte service-handler gevonden

  2. Ora SQL Query:deelnemen zonder referenties

  3. Hoe het PostgreSQL-dumpbestand in Postgres-databases te herstellen?

  4. NOT DISTINCT-query in mySQL