SQL sum with condition

前端 未结 3 1454
情话喂你
情话喂你 2020-11-30 23:46

I currently have a large SQL statement which i add the following line to in order to get the total cash for each transaction ID (which are unique):

select su         


        
3条回答
  •  广开言路
    2020-11-30 23:50

    With condition HAVING you will eliminate data with cash not ultrapass 0 if you want, generating more efficiency in your query.

    SELECT SUM(cash) AS money FROM Table t1, Table2 t2 WHERE t1.branch = t2.branch 
    AND t1.transID = t2.transID
    AND ValueDate > @startMonthDate HAVING money > 0;
    

提交回复
热议问题