QUOTE(alien3d @ May 15 2017, 11:09 AM)
CODE
INSERT INTO `table2` ('a',(
SELECT SUM(harga)
FROM `table1`
WHERE id = 'a'
GROUP BY `a`
)
);
Dear ts.. sila rajin rajin guna tool macam
http://sqlfiddle.com/
CODE
GROUP BY `a`
This line of code practically does nothing. All the lines returned will contain records with 'a' as the ID. No point in grouping anything. The code below should give the same result.
CODE
insert into table2(id,total)
select 'a',sum(harga)
from table1
where id='a'
select 'a',sum(harga)
from table1
where id='a'
If you do need the grouping part, the code below would be better since all you need is a single change if you want the total for a different id.
CODE
insert into table2(id,total)
select id,sum(harga)
from table1
where id='a'
group by id
select id,sum(harga)
from table1
where id='a'
group by id
May 15 2017, 06:02 PM

Quote
0.0164sec
0.39
7 queries
GZIP Disabled