Is there any wrong code with my query to join table?

后端 未结 3 892
逝去的感伤
逝去的感伤 2021-01-26 06:28

I am really confused with this codes. I have query like this

CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `aIPK` AS select 
`i         


        
3条回答
  •  野的像风
    2021-01-26 06:55

    I don't know what the exact problem(s) is, but your WHERE clause has a problem:

    WHERE IPK IS NOT NULL
    

    It is not allowed to refer to a column alias in the WHERE clause, because its value may not be determined yet. Instead, you should use this:

    WHERE akdhis_kelanjutanstudi.IPK IS NOT NULL
    

    Update:

    The parentheses you used in your original view look strange, unnecessary, and possibly wrong. Try using the following:

    CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost`
        SQL SECURITY DEFINER VIEW aIPK AS
    SELECT t4.Kode AS Fakultas,
           t3.Kode AS Departemen,
           t1.NIM AS NIM,
           t1.TahunMasuk AS TahunMasuk,
           t6.IPK AS IPK
    FROM akdmst_mahasiswamagister t1
    LEFT JOIN akdmst_mayor t2
        ON t1.MayorID = t2.ID
    LEFT JOIN ipbmst_departemen t3
        ON t2.DepartemenID = t3.ID
    LEFT JOIN ipbmst_fakultason t4
        ON t3.FakultasID = t4.ID
    LEFT JOIN ipbmst_orang t5
        ON t1.NIM = t5.NIMS2Key
    LEFT JOIN akdhis_kelanjutanstudi t6
        ON t6.NIM = t5.NIMS2Key
    WHERE t6.IPK IS NOT NULL
    ORDER BY NIM
    LIMIT 100;
    

提交回复
热议问题