Welcome Guest ( Log In | Register )

Outline · [ Standard ] · Linear+

 mysql query help, help me

views
     
Eventless
post May 15 2017, 06:02 PM

Look at all my stars!!
*******
Senior Member
2,643 posts

Joined: Jan 2003
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/
whistling.gif
*
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'


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

Eventless
post May 15 2017, 06:05 PM

Look at all my stars!!
*******
Senior Member
2,643 posts

Joined: Jan 2003
QUOTE(phyckeryz @ May 15 2017, 10:01 AM)
hi master.. i hope can ask guide from u guys here..

my issue here how to sum data in one of table field and insert into second table the total value..  sweat.gif  sweat.gif
for ur easy understand i put the sample table figure below..  icon_question.gif  icon_question.gif

[attachmentid=8814800]

notworthy.gif  notworthy.gif how to query master.. icon_question.gif  icon_question.gif
*
Your table2 will essentially be the same as the result of the below query.
CODE
select id,sum(harga) as total
from table1
group by id


 

Change to:
| Lo-Fi Version
0.0164sec    0.39    7 queries    GZIP Disabled
Time is now: 22nd December 2025 - 06:56 AM