If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Calculation in SQL

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-25-03, 22:24
jdkitch jdkitch is offline
Registered User
 
Join Date: Nov 2003
Posts: 3
Calculation in SQL

I'll preface this by saying I'm pretty new in regards to SQL. I've looked for info on doing this, but haven't had much luck because I'm not exactly sure what I'm looking for or if it's even possible.

I'm trying to run a query against an order database. Within each record, I have a unit price and a qty. I was trying to run a query that would spit out a line item extended value by order. Such as....

select order_number Order, (unit_price * qty) Value
from order_line;

Outputting...

Order Value
===============
JRD76 $24.40
STY32 $78.27
etc
etc

I know the above syntax isn't "real", but I figured I should be able to do something along these lines, and just can't find the right way. Is it possible?

Thanks,
jdk
Reply With Quote
  #2 (permalink)  
Old 11-26-03, 00:44
r123456 r123456 is offline
Registered User
 
Join Date: Sep 2003
Location: The extremely Royal borough of Kensington, London
Posts: 778
It seems like you were missing the "As" word, providing all the data you need is in the same table (orders).

select order_id As "order", (qty * unit_price) As "Value"
from sample;
__________________
Bessie Braddock: Winston, you are drunk!
Churchill: And Madam, you are ugly. And tomorrow, I'll be sober, and you will still be ugly.
Reply With Quote
  #3 (permalink)  
Old 11-28-03, 06:20
shelva shelva is offline
Registered User
 
Join Date: Nov 2003
Location: Rotterdam, Netherlands
Posts: 127
Can you pls be more clear with your requirement
Reply With Quote
  #4 (permalink)  
Old 11-28-03, 13:44
Todd Barkus Todd Barkus is offline
Registered User
 
Join Date: Nov 2003
Location: down on the cube farm, left then right then another left
Posts: 467
I use Oracle so I can only speak to their flavor.

What you have is almost there. Part of your problem is that both 'Order' and 'Value' are key words (to Oracle). If you write:

select order_number "Order", (unit_price * qty) "Value"
from order_line;

You should be home ( by that I mean "it should work"). You could even drop the () if you like. Tell me if this works.

Todd
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On