SQL Quiz 2: Functions

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Anubkoshy
A
Anubkoshy
Community Contributor
Quizzes Created: 1 | Total Attempts: 1,372
Questions: 10 | Attempts: 1,378

SettingsSettingsSettings
SQL Quizzes & Trivia

Functions(Char,Concat,Substr etc) Date Functions Numeric Functions(Sum,Avg etc) Usage of group by and Having with aggregate functions Use of IFNull and Coalease functions Case expression


Questions and Answers
  • 1. 

    Which one of the following queries will select the Number of Unique Departments from the Department Table below Department Number               Employee Number 11 248525 11 267712 12 112456 11 234567 13 661231

    • A.

      Select count(*) from Department_Table

    • B.

      Select count(distinct DepartmentNumber) from Department_Table having distinct DepartmentNumber

    • C.

      Select count(distinct DepartmentNumber) from Department_Table

    • D.

      Select distinct departmentNumber from Department_Table

    Correct Answer
    C. Select count(distinct DepartmentNumber) from Department_Table
    Explanation
    The correct answer is "Select count(distinct DepartmentNumber) from Department_Table". This query will count the number of unique departments in the Department_Table by using the "distinct" keyword to eliminate duplicate values of DepartmentNumber. The "count" function will then count the number of distinct DepartmentNumbers remaining in the table.

    Rate this question:

  • 2. 

    The output from the function dec(-99.9999) would be

    • A.

      -99.9999

    • B.

      -99

    • C.

      99.9999

    • D.

      99

    Correct Answer
    B. -99
    Explanation
    The given function dec(-99.9999) would output -99. This is because the function is likely designed to truncate the decimal portion of the input number and return the integer value. In this case, the decimal value -99.9999 is truncated to -99, resulting in the output of -99.

    Rate this question:

  • 3. 

    How to display Number of days from today for a given date(2012-07-31)

    • A.

      Select date(‘2012-07-31’) – curdate() from sysibm/sysdummy1

    • B.

      Select ‘2012-07-31’ – date(curdate()) from sysibm/sysdummy1

    • C.

      Select ‘2012-07-31’ – curdate() from sysibm/sysdummy1

    • D.

      Select date(‘2012-07-31’) – date(curdate()) from sysibm/sysdummy1

    Correct Answer
    A. Select date(‘2012-07-31’) – curdate() from sysibm/sysdummy1
    Explanation
    The correct answer is "Select date('2012-07-31') - curdate() from sysibm/sysdummy1". This query subtracts the current date (curdate()) from the given date ('2012-07-31') to calculate the number of days between them.

    Rate this question:

  • 4. 

    The output of LTRIM(‘  Test Yourself’) || Strip(‘$when$ you have problem’,’B’,’$’) would be

    • A.

      Test Yourselfwhen$you have problem

    • B.

      Test Yourself when you have problem

    • C.

      Test Yourself$when you have problem

    • D.

      Test Yourself$when$you have problem

    Correct Answer
    A. Test Yourselfwhen$you have problem
    Explanation
    The LTRIM function removes any leading spaces from the string " Test Yourself". The Strip function removes any occurrences of the character "B" and the character "$" from the string "$when$ you have problem". Therefore, the output would be "Test Yourselfwhen$you have problem".

    Rate this question:

  • 5. 

     How to convert date YYYY-MM-DD to MMDDYYYY format

    • A.

      Substr(YYYY-MM-DD,6,2) || Substr(YYYY-MM-DD,9,2) || Substr(YYYY-MM-DD,1,4)

    • B.

      Concat(Substr(YYYY-MM-DD,9,2) , Substr(YYYY-MM-DD,6,2) , Substr(YYYY-MM-DD,1,4))

    • C.

      Substr(YYYY-MM-DD,9,2) || Substr(YYYY-MM-DD,6,2) || Substr(YYYY-MM-DD,1,4)

    • D.

      None of the above

    Correct Answer
    C. Substr(YYYY-MM-DD,9,2) || Substr(YYYY-MM-DD,6,2) || Substr(YYYY-MM-DD,1,4)
    Explanation
    The correct answer is the third option, "Substr(YYYY-MM-DD,9,2) || Substr(YYYY-MM-DD,6,2) || Substr(YYYY-MM-DD,1,4)". This answer suggests using the Substr function to extract the year, month, and day from the given date string, and concatenating them in the desired format of MMDDYYYY. The Substr function is used to extract a portion of a string based on the specified starting position and length. In this case, it is used to extract the year (Substr(YYYY-MM-DD,1,4)), month (Substr(YYYY-MM-DD,6,2)), and day (Substr(YYYY-MM-DD,9,2)) from the date string.

    Rate this question:

  • 6. 

    The output of day(‘2008-01-12’) would be same as that of day(’12.01.2008’)

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    The output of the day() function in both cases would be the same because the date format does not affect the result. The day() function extracts the day component from a given date, regardless of the format it is in. Therefore, whether the date is in the format '2008-01-12' or '12.01.2008', the day() function will extract the day component '12' in both cases.

    Rate this question:

  • 7. 

    What would the output of coalesce(NULLIF(4500.00,4500),’1’)

    • A.

      4500

    • B.

      1

    • C.

      Null

    • D.

      Error

    Correct Answer
    B. 1
    Explanation
    The coalesce function returns the first non-null value from the given arguments. In this case, the NULLIF function compares the first argument (4500.00) with the second argument (4500), and since they are equal, it returns null. Therefore, the coalesce function will return the next argument, which is '1'.

    Rate this question:

  • 8. 

    What would be output of the below query  Select max(min(SLSVLM)) from sales SLSVLM    SLSDate 1 20121010 12 20121110 5 20120111 2 20120111 -1 20120112 0 20120106

    • A.

      12

    • B.

      0

    • C.

      -1

    • D.

      Error

    Correct Answer
    C. -1
    Explanation
    The query is finding the minimum value of the column SLSVLM and then finding the maximum value from that result. In this case, the minimum value of SLSVLM is -1, and since it is the only value, it is also the maximum value. Therefore, the output of the query would be -1.

    Rate this question:

  • 9. 

    The output of the below query would be  Select  ISNULL(day(SLSDate),SUBSTR(SLSDATE,9,2)) from sales  SLSVLM    SLSDate 1 10/10/2012 12 10/11/2012 5 1/11/2012 2 1/11/2012 Note*: each value in an option is a row

    • A.

      NULL NULL 01 01

    • B.

      10 10 11 11

    • C.

      NULL 11 01 01

    • D.

      None of the above

    Correct Answer
    C. NULL 11 01 01
    Explanation
    The query is selecting the day component of the SLSDate column using the DAY() function. However, if the SLSDate column is NULL, it will instead select a substring of the SLSDATE column starting from the 9th character and with a length of 2 characters. In the given table, the SLSDate column is not NULL for any of the rows, so the DAY() function will be used. Since the DAY() function cannot be applied to a NULL value, the output will be NULL.

    Rate this question:

  • 10. 

     What would be the output of STRIP(‘555Dollor55Dollor555’,B,’5’)

    • A.

      55Dollor55Dollor55

    • B.

      Dollor55Dollor55

    • C.

      Dollor55Dollor

    • D.

      DollorDollor

    Correct Answer
    C. Dollor55Dollor
    Explanation
    The STRIP function is used to remove characters from a string. In this case, the function is removing the character '5' from the given string '555Dollor55Dollor555'. The function is also replacing the character 'B' with '5'. So, the output would be 'Dollor55Dollor'.

    Rate this question:

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 21, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Jul 23, 2012
    Quiz Created by
    Anubkoshy

Related Topics

Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.