none
query group and Sum number has got Conditional ?

    Question

  • 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 ?
    [CODE]
    //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;
    [/CODE]
    Sunday, November 27, 2016 10:16 AM

Answers