New answers tagged sum
-1
votes
How to Join two tables with SUM and GROUP BY in SQL server
SELECT Designation, SUM(Qty)
FROM Product P
JOIN sub_product Q
ON Q.Product_ID = P.id
GROUP BY Designation
ORDER BY Designation
? downvoted? LOL
DECLARE @Product TABLE (ID INT, Designation VARCHAR(10)...
3
votes
Accepted
How to Join two tables with SUM and GROUP BY in SQL server
This can be accomplished simply with a JOIN and GROUP_BY clause like so:
SELECT
p.designation,
SUM(ISNULL(sp.quantity, 0)) AS [total quantity]
FROM product AS p
LEFT JOIN sub_product AS sp
...
Top 50 recent answers are included
Related Tags
sum × 150mysql × 59
sql-server × 34
group-by × 33
join × 24
postgresql × 23
count × 13
select × 12
oracle × 9
query × 9
aggregate × 9
case × 8
window-functions × 6
distinct × 6
running-totals × 6
pivot × 5
sqlite × 4
performance × 3
sql-server-2014 × 3
mariadb × 3
subquery × 3
mysql-8.0 × 3
datetime × 3
union × 3
max × 3