Welcome Guest ( Log In | Register )

Outline · [ Standard ] · Linear+

 mysql query help, help me

views
     
alien3d
post May 15 2017, 11:09 AM

Look at all my stars!!
*******
Senior Member
3,740 posts

Joined: Mar 2009
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
*
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

This post has been edited by alien3d: May 15 2017, 11:10 AM
alien3d
post May 15 2017, 07:42 PM

Look at all my stars!!
*******
Senior Member
3,740 posts

Joined: Mar 2009
QUOTE(Eventless @ May 15 2017, 06:02 PM)
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

*
ah my mistake.. but still this question a bit odd by da way

 

Change to:
| Lo-Fi Version
0.0142sec    0.65    7 queries    GZIP Disabled
Time is now: 22nd December 2025 - 05:15 AM