开发者

Need T-SQL code for the following pseudo code [closed]

开发者 https://www.devze.com 2023-04-06 22:38 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.
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'
0

精彩评论

暂无评论...
验证码 换一张
取 消