I need to select top5. I got bad results when i coded like select top5
SELECT
d.CUSTNMBR Customer_ID,
d.CUSTNAME Customer_Name,
sum(d.SALES) Yearly_Total
FROM
(SELECT
s.GLPOSTDT, s.CUSTNMBR, s.CUSTNAME,
CASE s.SOPTYPE
when 3 then s.SUBTOTAL
when 4 then s.SUBTOTAL*-1
END SALES
FROM
SOP30200 s
LEFT OUTER JOIN
RM00101 c ON s.CUSTNMBR = c.CUSTNMBR
WHERE
s.VOIDSTTS = 0
AND s.SOPTYPE IN (3, 4)
AND YEAR(s.GLPOSTDT) = '2017') d
GROUP BY
d.CUSTNMBR, d.CUSTNAME
*This post is locked for comments
I have the same question (0)