dbTalk Databases Forums  

Multiplying Grouped Columns

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss Multiplying Grouped Columns in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
HLong
 
Posts: n/a

Default Multiplying Grouped Columns - 07-27-2005 , 01:21 PM






I have a query, which selects three columns from an inner join. The last two
columns are SUM and the first one is GROUP BY. Now, I would like to add
another column that will be the multiplication of the second and third
columns. I have tried many ways but I am not very sure if what I have come up
with is the best approach. Could someone suggest what would be the best way
to achieve something like this?

Reply With Quote
  #2  
Old   
Narayana Vyas Kondreddi
 
Posts: n/a

Default Re: Multiplying Grouped Columns - 07-27-2005 , 01:39 PM






Could you post your query first, along with table structures, sample data
and desired output? Otherwse we'll be guessing what you are trying to
achieve. Anyway, here's a guess:

select i, sum(j), sum(k), sum(j) * sum(k) from x group by i
--
HTH,
Vyas, MVP (SQL Server)
SQL Server Articles and Code Samples @ http://vyaskn.tripod.com/


"HLong" <HLong (AT) discussions (DOT) microsoft.com> wrote

Quote:
I have a query, which selects three columns from an inner join. The last
two
columns are SUM and the first one is GROUP BY. Now, I would like to add
another column that will be the multiplication of the second and third
columns. I have tried many ways but I am not very sure if what I have come
up
with is the best approach. Could someone suggest what would be the best
way
to achieve something like this?



Reply With Quote
  #3  
Old   
HLong
 
Posts: n/a

Default Re: Multiplying Grouped Columns - 07-27-2005 , 05:21 PM



Thank you very much. It was what I was looking for. I didn't know I could
do something like sum(J)*sum(k) :-(

"Narayana Vyas Kondreddi" wrote:

Quote:
Could you post your query first, along with table structures, sample data
and desired output? Otherwse we'll be guessing what you are trying to
achieve. Anyway, here's a guess:

select i, sum(j), sum(k), sum(j) * sum(k) from x group by i
--
HTH,
Vyas, MVP (SQL Server)
SQL Server Articles and Code Samples @ http://vyaskn.tripod.com/


"HLong" <HLong (AT) discussions (DOT) microsoft.com> wrote in message
news:48F966FD-3B4B-4E5D-80AB-76734EB3826E (AT) microsoft (DOT) com...
I have a query, which selects three columns from an inner join. The last
two
columns are SUM and the first one is GROUP BY. Now, I would like to add
another column that will be the multiplication of the second and third
columns. I have tried many ways but I am not very sure if what I have come
up
with is the best approach. Could someone suggest what would be the best
way
to achieve something like this?




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.