Results 1 to 8 of 8

Thread: SQL Help     submit to reddit submit to twitter

  1. #1
    Pandemonium
    Join Date
    Feb 2010
    Posts
    7,665
    BG Level
    8
    FFXI Server
    Sylph

    SQL Help

    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?

  2. #2
    Nidhogg
    Join Date
    Apr 2006
    Posts
    3,562
    BG Level
    7

    http://docs.oracle.com/cd/B28359_01/...03.htm#autoId0

    CREATE TABLE hr.admin_emp (
    empno NUMBER(5) PRIMARY KEY,
    ename VARCHAR2(15) NOT NULL,
    ssn NUMBER(9) ENCRYPT,
    job VARCHAR2(10),
    mgr NUMBER(5),
    hiredate DATE DEFAULT (sysdate),
    photo BLOB,
    sal NUMBER(7,2),
    hrly_rate NUMBER(7,2) GENERATED ALWAYS AS (sal/2080),
    comm NUMBER(7,2),
    deptno NUMBER(3) NOT NULL
    CONSTRAINT admin_dept_fkey REFERENCES hr.departments
    (department_id))
    or way more basic:

    create table tablename (
    columname columntype
    )

  3. #3
    Pandemonium
    Join Date
    Feb 2010
    Posts
    7,665
    BG Level
    8
    FFXI Server
    Sylph



    I know I'm being really stupid with something, but this is literally my first time ever looking at this.

    How do I create a table that has the two job fields?

    I've included an image of some fails.

  4. #4
    I don't care, make something up!
    Join Date
    Nov 2007
    Posts
    495
    BG Level
    4

    create table Job (
    jobid varchar(10) not null primary key,
    jobdescription varchar(10) null
    );

  5. #5
    Pandemonium
    Join Date
    Feb 2010
    Posts
    7,665
    BG Level
    8
    FFXI Server
    Sylph

    Yep, that was it. I didn't realize...well, it doesn't matter.

    Now it said Table created.

    Now to find the table......wonder how I view it.

  6. #6
    Smells like Onions
    Join Date
    Nov 2009
    Posts
    9
    BG Level
    0
    FFXI Server
    Sylph

    For your first table

    Sample:

    SQL> create table employee (EMPNUMBER NUMBER(10) PRIMARY KEY,
    2 EMPFIRSTNAME VARCHAR2(25),
    3 EMPLASTNAME VARCHAR2(25),
    4 COMMISSIONRATE NUMBER(5,2),
    5 YRLYSALARY NUMBER(10,2),
    6 DEPARTMENTID NUMBER(2),
    7 JOBID NUMBER(2));

    Assuming that the data you're putting in would cater to the length of the datatypes.

  7. #7
    Pandemonium
    Join Date
    Feb 2010
    Posts
    7,665
    BG Level
    8
    FFXI Server
    Sylph

    The way this reads, the data already exists in the database.

    It's like a 7 question assignment, and I have to figure out how to query between the tables to get results. I just posted the first question cause I was hitting my head on the wall.

    I think I still have to actually create the other tables still

  8. #8
    Salvage Bans
    Join Date
    Feb 2007
    Posts
    811
    BG Level
    5
    FFXIV Character
    Orinthia Warsong
    FFXIV Server
    Excalibur
    FFXI Server
    Bahamut

    You could try WAMP server to give yourself a local mysql engine. http://www.wampserver.com/en/ , get the 32bit 2.2E version (I've never had a good experience with the 2.4 or the 64bit versions).

    It's free, accessed through your browser (uses localhost), and lets you run php, sql, etc locally. You can make tables and such through the phpmyadmin interface to see how they're supposed to work, but it also has a command box you can type your statements into and run like from a command prompt. You can export the created tables and such as a text command file, setup triggers, run test queries, etc. Was invaluable for testing when I took sql classes.

    There's also Dia, http://dia-installer.de/ , a free and relatively low power diagramming tool if you're not using visio or something fancier. And RAT, http://www.slinfo.una.ac.cr/rat/rat.html , relation algebra translator, if your class goes over relation algebra in the future.

    And try this for the employee table:
    Code:
    CREATE TABLE `Employee` (
      `EmpNumber` int(5) unsigned NOT NULL,
      `EmpFirstName` varchar(50) NOT NULL,
      `EmpLastName` varchar(50) NOT NULL,
      `CommissionRate` float NOT NULL,
      `YrlySalary` float NOT NULL,
      `DepartmentID` int(5) unsigned NOT NULL,
      `JobID` int(5) unsigned NOT NULL,
      PRIMARY KEY (`EmpNumber`)
    );
    Not much thought was put into the code.
    Apparently the phpmyadmin outputted accent marks (`) instead of apostrophes ('), not sure if that'll make a difference for you but those worked to just input a table on my end anyway.

Similar Threads

  1. SQL help
    By Saga in forum Tech
    Replies: 3
    Last Post: 2012-11-29, 19:24
  2. SQL help
    By saracrow in forum Tech
    Replies: 4
    Last Post: 2011-07-01, 00:22