Oracle Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesOracle Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old May 5th, 2008, 03:41 PM
theoryTim theoryTim is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2006
Posts: 99 theoryTim User rank is Sergeant (500 - 2000 Reputation Level)theoryTim User rank is Sergeant (500 - 2000 Reputation Level)theoryTim User rank is Sergeant (500 - 2000 Reputation Level)theoryTim User rank is Sergeant (500 - 2000 Reputation Level)theoryTim User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 48 m 50 sec
Reputation Power: 8
Can you help me with this query?

I have this lab and I really have no idea where to start. I read the chapter in-depth over 2 times and still am quite clueless...

The short version of the task at hand:

Determine which books generate less than 55% profit and how many copies of those books were sold.

I am working with (what tables I think i'll need to incorporate) two tables and the structures are as follows:

BOOKS table
isbn
title
cost
retail

ORDERITEMS table
order#
item#
isbn
quantity

I know to get profit is AVG(retail-cost) and I know what NEEDS to be done (JOIN using the isbn column), just can't figure out the syntax.

Help/hints would be greatly appreciated

Last edited by theoryTim : May 5th, 2008 at 03:44 PM.

Reply With Quote
  #2  
Old May 6th, 2008, 04:36 AM
debasisdas debasisdas is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2007
Location: Bangalore, India
Posts: 49 debasisdas Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 1 Day 12 h 51 m 13 sec
Reputation Power: 0
Send a message via ICQ to debasisdas Send a message via AIM to debasisdas Send a message via MSN to debasisdas Send a message via Yahoo to debasisdas Send a message via Google Talk to debasisdas Send a message via Skype to debasisdas
Facebook MySpace Orkut
for simple join try this syntax and replace your actual field name

Code:
select b.f1,b.f2,b.f3,o.f1,o.f2,o.f3 from books b ,orderitems o where b.isbn=o.isbn

Reply With Quote
  #3  
Old May 6th, 2008, 07:20 PM
theoryTim theoryTim is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2006
Posts: 99 theoryTim User rank is Sergeant (500 - 2000 Reputation Level)theoryTim User rank is Sergeant (500 - 2000 Reputation Level)theoryTim User rank is Sergeant (500 - 2000 Reputation Level)theoryTim User rank is Sergeant (500 - 2000 Reputation Level)theoryTim User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 48 m 50 sec
Reputation Power: 8
Yes I understand the syntax of the join, just to limit the results of the books that are below 55% of the profit is what is confusing me.

Something like

HAVING AVG(retail-cost) < .55

This is what I don't understand - the rest of the problems of the lab were easy.

Reply With Quote
  #4  
Old May 6th, 2008, 10:37 PM
clivew clivew is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2006
Location: Carlsbad, CA
Posts: 713 clivew User rank is Sergeant (500 - 2000 Reputation Level)clivew User rank is Sergeant (500 - 2000 Reputation Level)clivew User rank is Sergeant (500 - 2000 Reputation Level)clivew User rank is Sergeant (500 - 2000 Reputation Level)clivew User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 3 Days 17 h 48 m 33 sec
Reputation Power: 12
I think you need something like this:

SQL Code:
Original - SQL Code
  1. SELECT B.TITLE, SUM(O.QUANTITY)
  2. FROM ORDERITEMS O
  3. JOIN BOOKS B ON (O.ISBN = B.ISBN)
  4. WHERE ( B.RETAIL < (B.COST * 1.55) )
  5. GROUP BY B.TITLE


You do not need the AVG function.
Cost and retail are in the BOOKS table not the ORDERITEMS table so the relationship is constant
(at least as per your information)

Clive
Comments on this post
theoryTim agrees: Thanks!

Reply With Quote
  #5  
Old May 7th, 2008, 11:39 AM
theoryTim theoryTim is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2006
Posts: 99 theoryTim User rank is Sergeant (500 - 2000 Reputation Level)theoryTim User rank is Sergeant (500 - 2000 Reputation Level)theoryTim User rank is Sergeant (500 - 2000 Reputation Level)theoryTim User rank is Sergeant (500 - 2000 Reputation Level)theoryTim User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 48 m 50 sec
Reputation Power: 8
clivew, thank you muchly for your reply. Can you please explain to me how you came up with 1.55?

Reply With Quote
  #6  
Old May 7th, 2008, 12:04 PM
clivew clivew is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2006
Location: Carlsbad, CA
Posts: 713 clivew User rank is Sergeant (500 - 2000 Reputation Level)clivew User rank is Sergeant (500 - 2000 Reputation Level)clivew User rank is Sergeant (500 - 2000 Reputation Level)clivew User rank is Sergeant (500 - 2000 Reputation Level)clivew User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 3 Days 17 h 48 m 33 sec
Reputation Power: 12
Quote:
Originally Posted by theoryTim
clivew, thank you muchly for your reply. Can you please explain to me how you came up with 1.55?

A profit of 55% requires a selling price of 1.55 * Cost Price.

Cost + 55/100*Cost = Cost * 1.55

Clive

Reply With Quote
  #7  
Old May 7th, 2008, 12:33 PM
theoryTim theoryTim is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2006
Posts: 99 theoryTim User rank is Sergeant (500 - 2000 Reputation Level)theoryTim User rank is Sergeant (500 - 2000 Reputation Level)theoryTim User rank is Sergeant (500 - 2000 Reputation Level)theoryTim User rank is Sergeant (500 - 2000 Reputation Level)theoryTim User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 48 m 50 sec
Reputation Power: 8
Thank you soooooo much clivew! That cleared everything right up for me. My head-ache may now start to dull and settle down...

Thanks man for explaining all of that to me.


Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > Can you help me with this query?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway