0

I'm attempting to insert some data with MySQL using a subquery like so:

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);

but I get only error 1241, operand should contain 1 column(s)

How can I fix my query?

dg99
  • 5,456
  • 3
  • 37
  • 49
Chairul
  • 147
  • 1
  • 13

1 Answers1

2

group by should be on individual columns and comma separated.
They should not be a grouped as a set.

Remove parenthesis ( and ) in group by clause.

Example:

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>

Change:

GROUP BY (jasa_sk,waktu_sk);

To:

GROUP BY jasa_sk, waktu_sk;
Ravinder Reddy
  • 23,692
  • 6
  • 52
  • 82