Table A: | BillToName | Current| Total |
-----------------------------
| Company29 | N | 100 |
-----------------------------
| Company02 | Y | 80 |
-----------------------------
I need T-SQL for the following pseudo code:
SELECT BillToName, SUM(Total *regardless if the status is "Y" or "N") WHERE Current = 'Y'
Feel free to ask questi开发者_开发百科ons. Thanks!
I think you mean something like:
SELECT BillToName, SUM(Total)
FROM Table
WHERE BillToName IN (SELECT BillToName FROM Table WHERE Current = 'Y')
GROUP BY BillToName
SELECT a.BillToName, b.Total
FROM TableA a
CROSS APPLY (SELECT SUM(Total) Total FROM TableA) b
WHERE Current = 'Y'
select billtoname,(select sum(total) from table)
where current='Y'
精彩评论