Reply
Query in SQL Plus (aka Oracle) help, please!
Old 02-24-2009, 10:00 PM Query in SQL Plus (aka Oracle) help, please!
Junior Talker

Posts: 1
Trades: 0
So, I'm learning SQL and one of my practices is to,

" Determine what departments are in each of the 4 regions. That is, what are the names of the departments that reside in each of the regions."
So basically it wants me to list the departments in each region.

However, I'm just really confused as to where to start.
This is what the tables look like that it could possibly be drawn from...

Regions
region_id
region_name

Departments
department_id
department_name
manager_id
location_id

Locations
location_id
street_address
postal_code
city
state_province
country_id

Countries
country_id
country_name
region_id

Does anyone have any guesses on what to do/ where to start?

mikami is offline
Reply With Quote
View Public Profile
 
 
When You Register, These Ads Go Away!
Old 02-25-2009, 02:02 PM Re: Query in SQL Plus (aka Oracle) help, please!
chrishirst's Avatar
Super Moderator

Posts: 26,496
Location: Blackpool. UK
Trades: 0
Code:
SELECT R.region_name,D.department_id,D.department_name FROM regions AS R
   LEFT JOIN countries AS C ON C.region_id = R.region_id
  LEFT JOIN locations AS L ON C.country_id = L.country_id
   LEFT JOIN departments AS D on D.location_id = L.location_id;
Looks like it would work
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Growing old is mandatory - Growing up is optional
Code Samples | Crowded Nightclub? | Bits & Bobs
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 03-13-2009, 09:18 AM Re: Query in SQL Plus (aka Oracle) help, please!
Junior Talker

Posts: 1
Trades: 0
Hey, I'm new to using sql*plus (I'm learning it at uni)
the tables im working with are structured in the following way:

Suppliers Table has fields:
"SuppCode" and "SuppName"

Stocks Table has fields:
"StoreCode", "Description", "Quantity", "Units", "ReorderLevel", "Price", "SuppCode"

I have to write a query which displays the SuppName for all the suppliers which supply at least 4 stores.

I already have the following part-query which displays the SuppCode for the correct Suppliers, but I don't know how to then display the SuppName for the corresponding SuppCode's.

My query so far is:

Select SuppCode, COUNT(Distinct StoreCode)
From Stocks
Group By SuppCode
Having COUNT(Distinct StoreCode) >= 4;

Any help/hints would be greatly appreciated. Thanks in advance, Simon
Simon#1 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Query in SQL Plus (aka Oracle) help, please!
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.10067 seconds with 13 queries