Showing posts with label sum. Show all posts
Showing posts with label sum. Show all posts

Wednesday, March 21, 2012

nested Sum and DistinctCount error. Help!

Hi I'm really a newb at CR, (started this monday), and I wanted to do a statement like this:

Sum(DistinctCount({db_column3}, {db_column2}), {db_column1})

where the db_column1 can have many db_column2, and db_column2 can have many (repetitious) db_column3.

I'm assuming this wont work because one can't have a sum of a count, but what can I write that is to this effect? thanks a lot in advance!

Tom

Edit, i just tried doing Sum(DistinctCount(blah.. on something trivial, and it worked. So perhaps there are some constraints on the Cond in Sum(blah, Cond) that I don't know. Any enlightenment is much appreciated!>>i just tried doing Sum(DistinctCount(blah.. on something trivial, and it worked.

Then where are you struggling?

Monday, March 19, 2012

Nested Query Troubles...

Hi All,

Can anybody please tell me if a query such as this (Valid in MS Access)
can work in SQL Server:

SELECT Description, Sum(Total) FROM (
SELECT Description, Total FROM Table_A
UNION ALL
SELECT Description, Total FROM Table_B
UNION ALL
SELECT Description, Total FROM Table_C
)
GROUP BY Description


The group of unions work by themselves, but when I try to nest an outer query to do some a Summation(), I have syntax errors.

Any insight would be greatly appreciated. Thank you.You must supply an alias for your subquery:
SELECT Description,
Sum(Total)
FROM (SELECT Description,
Total
FROM Table_A
UNION ALL
SELECT Description,
Total
FROM Table_B
UNION ALL
SELECT Description,
Total
FROM Table_C) AS SUBQUERY
GROUP BY Description|||Thanks BlindMan, u da man.

:)

Nested Query (Urgent)

Folks

I have two queries

Select Account_Id , Branch_Cd from Accounts

SELECT SUM (dbo.HOLDING.Shares_Par_Value_Qty * dbo.ASSET.Current_Prc) AS MarketValue
FROM dbo.HOLDING INNER JOIN
dbo.ASSET ON dbo.HOLDING.Property_Num = dbo.ASSET.Property_Num
Group by dbo.HOLDING.Account_ID

Account_ID is the same in both the queries ie in both the tables
Holding and Account.

I need the output like this

Select Account_Id, Branch_Cd, MarketValue from ---

But MarketValue should be calculated exactly in the above method.
How do I combine these two queries. I need it asap.
Help me out.

ThanksCheck my reply to your SUM post. If it isn't clear from that then get back to me.

Ursus|||How about:

SELECT A.Account_Id , A.Branch_Cd, B.MarketValue
FROM Accounts AS A
INNER JOIN
( SELECT SUM (dbo.HOLDING.Shares_Par_Value_Qty * dbo.ASSET.Current_Prc) AS MarketValue
FROM dbo.HOLDING
INNER JOIN dbo.ASSET
ON dbo.HOLDING.Property_Num = dbo.ASSET.Property_Num
GROUP BY dbo.HOLDING.Account_ID ) AS B
ON A.Account_ID = B.Account_ID

Monday, February 20, 2012

Need to sum columns

I need to create a view (I believe) that will take a column named
'accountbalance' for a group of records, and total (sum) up those entries...
can someone point me to a tutorial to learn how to do this? THanks!
Never mind.. I found a reference. thanks tho

Need to sum columns

I need to create a view (I believe) that will take a column named
'accountbalance' for a group of records, and total (sum) up those entries...
can someone point me to a tutorial to learn how to do this? THanks!Never mind.. I found a reference. thanks tho

Need to sum columns

I need to create a view (I believe) that will take a column named
'accountbalance' for a group of records, and total (sum) up those entries...
can someone point me to a tutorial to learn how to do this? THanks!Never mind.. I found a reference. thanks tho