How Do I Combine Multiple Select Statements In Separate Columns?
I have these three statements: select count (distinct vid) as SUM_OF_SEC from pdalis where pid in(500,504); select sum (amount*paidperitem) SUM_OF_A from pdalis where pid = 501 ; s
Solution 1:
Try This by Subquery
selectcount (distinct vid) as SUM_OF_SEC ,(select sum (amount*paidperitem) from pdalis where pid = 501 ;) AS SUM_OF_A , (selectsum(amount * paidperitem) from pdalis where pid IN (500,504);) as SUM_OF_P from pdalis where pid in(500,504);
Solution 2:
Try like this.
SELECT TMP1.SUM_OF_SEC, TMP2.SUM_OF_A, TMP3.SUM_OF_P FROM
(select count (distinct vid) as SUM_OF_SEC from pdalis where pid in(500,504)) AS TMP1,
(select sum (amount*paidperitem) as SUM_OF_A from pdalis where pid = 501 ) AS TMP2,
(select sum(amount * paidperitem) as SUM_OF_P from pdalis where pid IN (500,504)) AS TMP3
Solution 3:
selectcount (distinct (Casewhen pid!=501then vid End)) as SUM_OF_SEC ,
sum (Casewhen pid=501then (amount*paidperitem) Else0End) as SUM_OF_A ,
sum(Casewhen pid!=501then (amount * paidperitem) Else0End)as SUM_OF_P from
pdalis where pid IN (500,504,501);
Solution 4:
SELECT CellPhone.PhoneNumber, SUM(BillingHistory.AmountOwed) AS TotalOwed
FROM Relationship
INNERJOIN CellPhone ON CellPhone.PKCellPhone = Relationship.FKCellPhone
INNERJOIN BillingHistory ON Relationship.PKRelationship = BillingHistory.FKRelationship
GROUPBY Relationship.PKRelationship, CellPhone.PhoneNumber
More Information You Can Go On
http://social.msdn.microsoft.com/Forums/en-US/1b035516-440d-47d6-ae75-cdb8926f1138/combine-columns-from-two-select-statements?forum=transactsql
Post a Comment for "How Do I Combine Multiple Select Statements In Separate Columns?"