query group and Sum number has got Conditional ?


Author
Message
Dong Trien Lam
Dong Trien Lam
StrataFrame Novice (105 reputation)StrataFrame Novice (105 reputation)StrataFrame Novice (105 reputation)StrataFrame Novice (105 reputation)StrataFrame Novice (105 reputation)StrataFrame Novice (105 reputation)StrataFrame Novice (105 reputation)StrataFrame Novice (105 reputation)StrataFrame Novice (105 reputation)
Group: Anonymous / Guest
Posts: 57, Visits: 251
I have the following SQL Server query:
requirements SUM and GROUP column SOLUONG AS SL , if TRAHANG = true then bring positive column opposite quantity quantity column value is negative, no team and no columns SL sum is, if I would give TRAHANG column in the SELECT statement error. Can you help me ?
//Query warning eror
SELECT TABHDBHCT.MAVACH_SP, TABHDBHCT.TENSP, SUM(TABHDBHCT.SOLUONG)*CASE WHEN [TRAHANG] = 0 THEN 1 ELSE -1 END AS SL
FROM TABHDBHCT INNER JOIN
     TABHDBH ON TABHDBHCT.MASOPHIEU = TABHDBH.IDSOPHIEU
WHERE (TABHDBH.TTTHANHTOAN = 1 OR
      TABHDBH.TTTHANHTOAN = 2) AND (TABHDBH.NGAY BETWEEN '11/01/2016' AND '11/30/2016')
GROUP BY TABHDBHCT.MAVACH_SP, TABHDBHCT.TENSP
ORDER BY TABHDBHCT.TENSP;

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search