如何实现“从(选择结果)在列名='列名'中显示栏”?

时间:2019-12-15 10:26:15

标签: mysql sql xampp

我的兄弟姐妹们都很好。

我要检查选择结果中是否存在一列。

我已经尝试了如下操作,但是却给了我一个错误。

SHOW COLUMNS 
    FROM (SELECT
                    hasil.skpd, hasil.kode_skpd, SUM(hasil.sudah_isi) AS sudah_isi, SUM(hasil.belum_isi) AS belum_isi
                FROM
                    (
                        SELECT
                            a.id_pegawai, c.skpd, c.kode_skpd, a.id_satuan_organisasi, a.nama_pegawai, a.nip,
                            CASE
                                WHEN i.id_pegawai IS NULL THEN 0
                                ELSE 1
                            END AS sudah_isi,
                            CASE
                                WHEN i.id_pegawai IS NULL THEN 1
                                ELSE 0
                            END AS belum_isi
                        FROM
                            tbl_pegawai a
                            LEFT JOIN ref_skpd c ON a.id_satuan_organisasi = c.id_skpd
                            LEFT JOIN tbl_bapertarum i ON (a.id_pegawai = i.id_pegawai AND YEAR(i.tgl_lapor)='2015')
                        GROUP BY
                            a.id_pegawai
                    ) hasil
                WHERE
                    1 AND hasil.kode_skpd LIKE 'Badan Kepegawaian Daerah%'
                GROUP BY
                    hasil.id_satuan_organisasi
                ORDER BY
                    hasil.kode_skpd) WHERE Field = "kode_skpd"

这是完整的错误结果:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '(SELECT
                    hasil.skpd, hasil.kode_skpd, SUM(hasil.sudah_isi) AS s' at line 2

如何从SELECT结果中找到一个或多个列的存在?

预先感谢兄弟姐妹。

0 个答案:

没有答案