i




 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
query group and Sum number has got Conditional ?
11-27-2016, 10:04 AM
Post: #1
query group and Sum number has got Conditional ?
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;



Quote


Possibly Related Threads...
Thread: Author Replies Views: Last Post
  What is Group by clause in SQL? magnum_2007 0 825 01-31-2013 07:50 AM
Last Post: magnum_2007
  Count Number Of Stored Procedures in Database Shafiur Rahman 3 4,531 07-18-2011 04:44 AM
Last Post: Jayakumar
  Count Number Of Stored View in Database Shafiur Rahman 3 2,656 04-10-2011 06:20 PM
Last Post: Rajesh Kumar Parbat
  How to get Number of Days in A Month Rajesh Kumar Parbat 3 2,150 12-10-2010 05:34 AM
Last Post: Usman



User(s) browsing this thread: 1 Guest(s)