SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 I have no idea what I'm doing....
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

SQL Confused
Starting Member

2 Posts

Posted - 10/18/2013 :  18:22:42  Show Profile  Reply with Quote
Hey all,

I'm taking a class on SQL databases, and I'm struggling cause it's online so examples are lacking, and the ability to ask questions are limited.

I have this assignment:

The Oracle Server may be used to test and compile the SQL Queries developed for this assignment. Your instructor will provide you with login credentials to a University maintained Oracle server.

Imagine that you have been hired as a consultant to assist in streamlining the data processing of an international based organization that sells high-end electronics. The organization has various departments such as payroll, human resources, finance, marketing, sales, and operations. The sales department is the only department where employees are paid a commission in addition to their yearly salary and benefits. All other departments compensate their employees with a yearly salary and benefits only. Commission is paid by multiplying the employee’s commission rate by the total amount of product units sold. You have access to the following data sets:
Employee (EmpNumber, EmpFirstName, EmpLastName, CommissionRate, YrlySalary, DepartmentID, JobID)

Invoice (InvNumber, InvDate, EmpNumber, InvAmount)

InvoiceLine (InvLineNumber, InvNumber, ProductNumber, Quantity)

Product (ProductNumber, ProductDescription, ProductCost)

Department (DepartmentID, DepartmentDescription)

Job (JobID, JobDescription)

Design a query that will allow the finance department to determine the commissions paid to specific employees of the sales department for the month of December. Note: You will need to generate the tables described above (Employee, Invoice, InvoiceLine, Product, Department, and Job) in order to compare and validate your code. Validated query code must be part of your paper.
I know this is incredibly basic, but how do I generate the query code?

As an example, I've tried:

create table employee (
column 1 empnumber
column 2 emplastname
column 3 empfirstname );

just to try to generate a table so I know I have the syntax right.

But despite my variations, I keep getting errors thrown at me. I know this is pretty basic, but can anyone give me an example of a working query?

tkizer
Almighty SQL Goddess

USA
36834 Posts

Posted - 10/18/2013 :  18:28:37  Show Profile  Visit tkizer's Homepage  Reply with Quote
You'll want to post your question on a site that's for Oracle. SQLTeam.com is for Microsoft SQL Server and sometimes Microsoft Access.

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

SQL Confused
Starting Member

2 Posts

Posted - 10/18/2013 :  18:40:00  Show Profile  Reply with Quote
And good times.

Thanks for the response.
Go to Top of Page

bitsmed
Constraint Violating Yak Guru

364 Posts

Posted - 10/19/2013 :  06:46:43  Show Profile  Reply with Quote
Maybe this (You have to fill in some data to test on yourself)

create table department (
   departmentid number
  ,departmentdescription varchar2(255)
  ,constraint pk_department primary key(departmentid)
);

create table product (
   productnumber number
  ,productdescription varchar2(255)
  ,productcost number(13,2)
  ,constraint pk_product primary key(productnumber)
);

create table job (
   jobid number
  ,jobdescription varchar2(255)
  ,constraint pk_job primary key(jobid)
);

create table employee (
   empnumber number
  ,empfirstname varchar2(255)
  ,emplastname varchar2(255)
  ,commissionrate number(13,2)
  ,yrlysalary number(13,2)
  ,departmentid number
  ,jobid number
  ,constraint pk_employee primary key(empnumber)
  ,constraint fk_employee_department foreign key (departmentid) references department(departmentid)
  ,constraint fk_employee_job foreign key (jobid) references job(jobid)
);

create table invoice (
   invnumber number
  ,invdate date
  ,empnumber number
  ,invamount number(13,2)
  ,constraint pk_invoide primary key(invnumber)
  ,constraint fk_invoice_employee foreign key (empnumber) references employee(empnumber)
);

create table invoiceline (
   invlinenumber number
  ,invnumber number
  ,productnumber number
  ,quantity number
  ,constraint pk_invoiceline primary key(invnumber,invlinenumber)
  ,constraint fk_invoiceline_invoice foreign key (invnumber) references invoice(invnumber)
  ,constraint fk_invoiceline_product foreign key (productnumber) references product(productnumber)
);

select *
  from employee as a
       inner join department as b
               on b.departmentid=a.departmentid
       inner join invoice as c
               on c.empnumber=a.empnumber
 where b.departmentdescription='Sales'
   and c.invdate between to_date('20121201','YYYYMMDD') and to_date('20121231','YYYYMMDD')
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000