Page 1 of 1

i want solution for that

Posted: Sat Aug 01, 2015 10:46 am
by pankajkumar
Hi,
I want a solution for
Suppose there is a table called Emp in that there is 2 column
First column is emp name X,X,Y,Y and second column is salary
1000 ,2000,3000,4000.
Write a code to display sum of the same emp name ,
Like
X+X=3000,
Thank you

Re: i want solution for that

Posted: Sat Aug 01, 2015 11:14 am
by Christopher
SELECT name, SUM(salary) AS total FROM Emp GROUP BY name

Re: i want solution for that

Posted: Mon Aug 03, 2015 9:12 pm
by s.dot
Christopher has provided an SQL solution. Assuming MySQL, displaying it in your web page would require usage of mysql_query(), and mysql_result() / mysql_fetch_assoc() / or mysql_fetch_array(). And then print()/echo your results in your web page or template.