Page 3 of 5 FirstFirst 12345 LastLast
Results 21 to 30 of 46

Thread: SQL Quiz!

  1. #21
    Junior Member
    Join Date
    Jun 2005
    Gender
    Male
    Posts
    285

    Default Re: SQL Quiz!


    MySQL ra man gud cge gamit nako..

  2. #22

    Default Re: SQL Quiz!

    next napud.

  3. #23

    Default Re: SQL Quiz!

    Quote Originally Posted by otis
    Quote Originally Posted by kobmat
    Sakto ni bai?

    SELECT MONTH(ORDERS_H.TRANSACTION_DATE) AS MON,
    CUSTOMER.CUSTOMER_NAME,
    SUM(ORDERS_D.SELLING_PRICE) AS TOTAL_PURCHASES
    FROM ORDERS_D, ORDERS_H, CUSTOMER
    WHERE ORDERS_D.RECORD_NO = ORDERS_H.RECORD_NO AND
    ORDERS_H.CUSTOMER_CODE = CUSTOMER.CUSTOMER_CODE
    GROUP BY MON, ORDERS_H.CUSTOMER_CODE;
    Sorry for the late reply, I've been busy sa work.

    Yes, I believe that's correct.. pero
    GROUP BY MON
    wouldn't work in MS SQL Server.

    GROUP BY MONTH(ORDERS_H.TRANSACTION_DATE) would work or you could create a derived table having MON as a column ;D
    Another way of joining tables and fields is by using table ALIAS. This helps much
    in writing faster your scripts kay dili naman ka mo type sa whole table name.

    SELECTÂ* Â* MONTH(h.TRANSACTION_DATE) AS MON,
    Â* Â* Â* Â* Â* Â* Â* Â*c.CUSTOMER_NAME,
    Â* Â* Â* Â* Â* Â* Â* Â*SUM(d.SELLING_PRICE) AS TOTAL_PURCHASESÂ* Â*
    FROM Orders_D d, Orders_H h, Customer c
    WHEREÂ* Â* d.RECORD_NO = h.RECORD_NO AND
    Â* Â* Â* Â* Â* Â* Â* Â*h.CUSTOMER_CODE = c.CUSTOMER_CODEÂ* Â*
    GROUP BY MON, h.CUSTOMER_CODE;

    In SQL (ANSI) you can also use JOIN ON and USING as your connectors eliminating the WHERE CLAUSE

    Using ON:

    SELECTÂ* Â* Â*MONTH(h.TRANSACTION_DATE) AS MON,
    Â* Â* Â* Â* Â* Â* Â* Â* Â*c.CUSTOMER_NAME,
    Â* Â* Â* Â* Â* Â* Â* Â* Â*SUM(d.SELLING_PRICE) AS TOTAL_PURCHASESÂ* Â*
    FROMÂ* Â* Â* Â* Orders_D d JOIN Orders_H ON (d.RECORD_NO = h.RECORD_NO)
    Â* Â* Â* Â* Â* Â* Â* Â* Â*AND Customer c JOIN Orders_D d ON (h.CUSTOMER_CODE = c.CUSTOMER_CODE)
    GROUP BY MON, h.CUSTOMER_CODE;

    Using:

    SELECTÂ* Â* Â*MONTH(h.TRANSACTION_DATE) AS MON,
    Â* Â* Â* Â* Â* Â* Â* Â* Â*c.CUSTOMER_NAME,
    Â* Â* Â* Â* Â* Â* Â* Â* Â*SUM(d.SELLING_PRICE) AS TOTAL_PURCHASESÂ* Â*
    FROMÂ* Â* Â* Â* Orders_D d JOIN Orders_H USING (RECORD_NO)
    Â* Â* Â* Â* Â* Â* Â* Â* Â*AND Customer c JOIN Orders_D d USING (CUSTOMER_CODE)
    GROUP BY MON, h.CUSTOMER_CODE;

    *** The MONTH() function works in MSSQL and mySQL but not in Oracle. A function TO_CHAR
    is used to change and return the desired format.

    SELECT TO_CHAR(h.TRANSACTION_DATE,'MM') AS MON,

    -- 'MM' stands for numeric month ex. May - 05, June - 06

  4. #24

    Default Re: SQL Quiz!

    In behalf of Kombat.

    SQL Quiz no.5

    Assume the following 2 table structures.

    Table: Employee Tableepartment
    Emp_id Dept_id
    Fname Dep_Name
    Lname Dep_Head
    Dept_id
    Salary

    What is the SQL statement to display ALL records found in the Employees Table
    and records in Department Table that has matched records in Employees Table?





  5. #25
    Junior Member
    Join Date
    Jun 2005
    Gender
    Male
    Posts
    285

    Default Re: SQL Quiz!

    Thank you bai.. naghimo pa man gud ko ug SQL Question na nindot...

  6. #26

    Default Re: SQL Quiz!

    Quote Originally Posted by kobmat
    Thank you bai.. naghimo pa man gud ko ug SQL Question na nindot...
    cge pardz i post ang ika number 6 many thanks

  7. #27
    Junior Member
    Join Date
    Jun 2005
    Gender
    Male
    Posts
    285

    Default Re: SQL Quiz!

    Cge pre.. humanon sa nako pre.. di man kaau ko expert SQL gud..

  8. #28
    Junior Member
    Join Date
    Jun 2005
    Gender
    Male
    Posts
    285

    Default Re: SQL Quiz!

    Quote Originally Posted by maldito_guapito
    In behalf of Kombat.

    SQL Quiz no.5

    Assume the following 2 table structures.

    Table: EmployeeÂ* Â* Â* Â* Â* Â* Tableepartment
    Emp_idÂ* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â*Dept_id
    FnameÂ* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Dep_Name
    LnameÂ* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Dep_Head
    Dept_id
    Salary

    What is the SQL statement to display ALL records found in the Employees Table
    and records in Department Table that has matched records in Employees Table?
    Wala ko kasabut sa question pre?

    pero i will try and answer..

    SELECT * FROM Employee WHERE deptid IN (SELECT * FROM Department)


  9. #29
    Junior Member
    Join Date
    Jun 2005
    Gender
    Male
    Posts
    285

    Default Re: SQL Quiz!

    SQL Quiz No. 6

    Table: EmployeeHours
    recordid
    employeeid
    timein (datetime ni cya)
    timeout (datetime ni cya)

    Table: Employees
    employeeid
    firstname
    lastname
    rateperhour

    I want to query the number of hours the employees spend working this week and the salary for this week presented neatly on with the following columns

    EmployeeName (in the format lastname comma firstname "Osmeña, Tomas")
    Hours
    Rateperhour
    Salary

    Wala ra ba ko idea unsaun ni.. still trying to solve this one.. hehehe


  10. #30

    Default Re: SQL Quiz!

    select lastname, firstname, sum(date(timeout)-date(timein)) as totaltime, rateperhour From emplooyeehours, employees where Employees.employeeid = EployeeHours.employeeid

    ambot lang kong sakto ba pero i think after makuha nimo ang sum(date(timeout)-date(timein)) i convert pa nimo into hrs. kai date man ang result ani.. then convertedhr * rateperhour = salary

  11.    Advertisement

Page 3 of 5 FirstFirst 12345 LastLast

Similar Threads

 
  1. o0 World's Easiest Quiz 0o
    By digital_pimpette in forum General Discussions
    Replies: 45
    Last Post: 12-02-2012, 07:47 PM
  2. SQL 101
    By BadDudes in forum Programming
    Replies: 44
    Last Post: 08-31-2012, 07:34 AM
  3. Tabangi ko plssss....PL/SQL Tuning Tips
    By zengatsu in forum Programming
    Replies: 13
    Last Post: 06-29-2006, 08:20 PM
  4. wat's d best sql back-end?
    By edshark in forum Software & Games (Old)
    Replies: 5
    Last Post: 09-15-2005, 04:41 PM
  5. HOW TO CONNECT SQL SERVER USING SQL AUTHENTICATION
    By edshark in forum Software & Games (Old)
    Replies: 13
    Last Post: 09-02-2005, 04:53 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
about us
We are the first Cebu Online Media.

iSTORYA.NET is Cebu's Biggest, Southern Philippines' Most Active, and the Philippines' Strongest Online Community!
follow us
#top