我正在尝试使用像这样的子查询在MySQL中插入一些数据:
INSERT
INTO dw_plynjasa.jumlah_fact
SELECT null, jasa_sk, waktu_sk, sum(hrg_pes), count(d.no_pes)
FROM dw_plynjasa.jasa_dim a,
dw_plynjasa.waktu_dim b,
oltp_plynjasa.detil_pesan c,
oltp_plynjasa.pesan d,
oltp_plynjasa.jasa e
WHERE b.tgl = d.tgl_pes
AND a.kd_jasa = e.kd_jasa
AND a.nm_jasa = e.nm_jasa
AND a.satuan = e.satuan
AND a.hrg_satuan = e.hrg_satuan
GROUP BY (jasa_sk, waktu_sk);
但我只获得error 1241, operand should contain 1 column(s)
如何修复查询?
答案 0 :(得分:1)
group by
应位于各个列上,并以逗号分隔
它们不应该被分组为集。
在(
子句中删除括号 )
和group by
。
示例:
mysql> select * from so.employee where 1=2 group by empno, deptno;
Empty set (0.00 sec)
mysql> select * from so.employee where 1=2 group by (empno, deptno);
ERROR 1241 (21000): Operand should contain 1 column(s)
mysql>
更改:
GROUP BY (jasa_sk,waktu_sk);
要强>:
GROUP BY jasa_sk, waktu_sk;