操作数应包含1列Codeigniter



我的查询可以吗?

public function parse()
{
$db4 = $this->load->database('db4', TRUE);
$query = $db4->query(' INSERT INTO test (nik, nama, status, bulan, tahun, hk, hb, lembur, gp, obat, transport, tunjangan, bpjs) SELECT (`karyawan`.`no_nik`, `karyawan`.`nama`, `karyawan`.`kd_status`, `absensi`.`bulan`, `absensi`.`tahun`, `absensi`.`hk`, `absensi`.`hari_besar`, `absensi`.`lembur`, `karyawan`.`gapok`, `karyawan`.`obat`, `karyawan`.`transport`, `karyawan`.`tunjangan`, `karyawan`.`bpjs`) FROM karyawan LEFT JOIN absensi ON `karyawan`.`no_nik` = `absensi`.`nik` ');
}

错误通知

我认为字段no_niknik不存在的karyawan.no_nik = absensi.nik部分的问题导致它在谈论:操作数

尝试在phpmyadmin或一些mysql-gui:中运行此查询

SELECT 
karyawan.no_nik    AS nik,
karyawan.nama,
karyawan.kd_status AS status,
absensi.bulan,
absensi.tahun,
absensi.hk,
absensi.hari_besar AS hb,
absensi.lembur,
karyawan.gapok     AS gp,
karyawan.obat,
karyawan.transport,
karyawan.tunjangan,
karyawan.bpjs
FROM karyawan
LEFT JOIN absensi ON (karyawan.no_nik = absensi.nik)

如果查询将成功,则括号内的作用域SELECT可以解决问题:

public function parse()
{
$db4 = $this->load->database('db4', TRUE);
$query = '
INSERT INTO test 
(nik, nama, status, bulan, tahun, hk, hb, lembur, gp, obat, transport, tunjangan, bpjs)
(
SELECT karyawan.no_nik    AS nik,
karyawan.nama,
karyawan.kd_status AS status,
absensi.bulan,
absensi.tahun,
absensi.hk,
absensi.hari_besar AS hb,
absensi.lembur,
karyawan.gapok     AS gp,
karyawan.obat,
karyawan.transport,
karyawan.tunjangan,
karyawan.bpjs
FROM karyawan
LEFT JOIN absensi ON (karyawan.no_nik = absensi.nik)
)
';
$query = $db4->query($query);
}

相关内容

  • 没有找到相关文章