please help for query...
i want sum (kns+kng) by name - example
the result should be:
name|sum
john - 36
bart - 16
steve - 53
jim - 10
tnx
Jump to PostThere may be an easier way, but I think this works:
SELECT `name`, SUM(sm) AS total FROM ((SELECT `name`, kns AS sm FROM tab1) UNION ALL (SELECT `name`, kng AS sm FROM tab2)) AS tbl GROUP BY tbl.name
You may benefit from using an user_id in …
There may be an easier way, but I think this works:
SELECT `name`, SUM(sm) AS total FROM ((SELECT `name`, kns AS sm FROM tab1) UNION ALL (SELECT `name`, kng AS sm FROM tab2)) AS tbl GROUP BY tbl.name
You may benefit from using an user_id in order to relate your tables properly.
@diafol
thank you very much, i really appreciate your answer
This is a very simplified example, i just want to learn how to do that
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.
You're trying to visit a URL that doesn't currently exist on the web. Most likely, a member posted a link a long time ago to a web page that has since been removed. It's also possible that there was a typo when posting the URL. We redirect you to this notice instead of stripping out the link to preserve the integrity of the post.