GROUP BY problem

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
frankvanlogten
Posts: 7
Joined: Sat 21 May 2011 09:18

GROUP BY problem

Post by frankvanlogten » Tue 24 May 2011 10:08

Hello,

I'm using the next SQL code:

SELECT p.unieknummer, SUM(p.verkoopprijs) AS verkoopprijs, (CASE WHEN k.hoofdproductcategorie IS NULL OR k.hoofdproductcategorie='' THEN 'LEEG' ELSE k.hoofdproductcategorie end) AS hoofdproductcategorie
FROM project AS p
LEFT OUTER JOIN projectkaart
AS k ON p.projectnummer = k.projectnummer
WHERE offerte_status = 'Opgeleverd'
AND opleverdatum >= '01-01-2009'
AND opleverdatum <= '31-12-2009'
GROUP BY unieknummer, hoofdproductcategorie
ORDER BY unieknummer

Which gives me the next result:
unieknummer verkoopprijs hoofdproductcategorie
1220 2274 LEEG
1220 839 LEEG
1350 175 LEEG
1350 1513 LEEG
1350 290 full color
1429 65 LEEG
1429 265 LEEG
1439 175 LEEG
1557 2040 LEEG
1615 396 LEEG
1639 35 LEEG
1641 0 LEEG
1641 8226 LEEG
1641 2876 full color
1691 875 LEEG
1691 3154 LEEG
1691 158 full color
..................................................................

However i want the following result:
unieknummer verkoopprijs hoofdproductcategorie
1220 3113 LEEG
1350 1688 LEEG
1350 290 full color
1429 330 LEEG
1439 175 LEEG
1557 2040 LEEG
1615 396 LEEG
1639 35 LEEG
1641 8226 LEEG
1641 2876 full color
1691 4029 LEEG
1691 158 full color
..................................................................

AndreyZ

Post by AndreyZ » Tue 24 May 2011 13:15

Please do not duplicate topics. I have answered you here: http://www.devart.com/forums/viewtopic.php?t=21068

Post Reply