Worksheets › Class 12 › Querying and SQL Functions

Class 12 · Informatics Practices worksheet

Querying and SQL Functions

CBSE Informatics Practices. Math, text and date functions, aggregate functions, GROUP BY and HAVING, ORDER BY, Cartesian product and equi-joins of two tables. Every sheet has 20 questions in three sections and an answer key, and the questions change every time.

Open a printable sample sheet

Sample questions

Real questions from this chapter, as the app sets them. Tap Answer to see the answer and working.

Section A · multiple choice

  1. 1.

    A single row function in SQL:

    1. works only on numbers
    2. can be used only after GROUP BY
    3. gives one result for the whole table
    4. gives one result for each row it is applied to
    Answer

    (d) gives one result for each row it is applied to

  2. 2.

    What does this query return? SELECT ROUND(926.716, 2);

    1. 926.73
    2. 927
    3. 926.72
    4. 926.716
    Answer

    (c) 926.72

    ROUND keeps 2 decimal places, rounding a 5 or more up

  3. 3.

    What does this query return? SELECT MID('Spreadsheet', 2, 3);

    1. pre
    2. rea
    3. Spr
    4. pr
    Answer

    (a) pre

    3 letters from position 2: pre

Section B · short answer

  1. 4.

    Name the three categories of single row functions in MySQL and give one example of each.

    Answer

    Math (numeric) functions, e.g. ROUND(); text (string) functions, e.g. LENGTH(); date functions, e.g. MONTH().

  2. 5.

    Write the output of: SELECT ROUND(861.398, 1);

    Answer

    861.4

    round 861.398 to 1 decimal place

Section C · long answer

  1. 6.

    Explain GROUP BY and HAVING with a suitable example query.

    Answer

    GROUP BY collects rows with the same value of a column into groups; an aggregate function then gives one value per group. HAVING keeps only the groups that satisfy a condition. Example: SELECT City, COUNT(*) FROM STUDENT GROUP BY City HAVING COUNT(*) > 2; lists each city with more than two students and the number of students.

    definition of each (2); a correct query (2)

Fresh sheets for your child

In the app, every Querying and SQL Functions sheet is new: the app remembers the questions your child has already had and leaves them out. Print the sheet as a PDF, or use notebook mode and write the answers in a notebook.

Coming soon for Android and iPhone.

More Class 12 Informatics Practices