Clicker Questions
to go with Modern Data Science with R, 3rd edition by Baumer, Kaplan, and Horton.
Many questions taken directly from * w3schools SQL quiz. * Java Guides * study.com
- What is a SQL server?.1
- A relational database management system.
- A software whose main purpose is to store and retrieve data.
- A highly secure server and does not allow any database file manipulation during execution.
- All of the above.
- When was SQL created?2
- 1960s
- 1970s
- 1980s
- 1990s
- 2000s
- What type of databases is SQL designed for?3
- hierarchical database management systems.
- network database management systems.
- object-oriented database management systems.
- relational database management systems.
- Which is bigger:4
- computer’s hard drive / storage
- computer’s memory / RAM
- Where are each stored?5
- SQL
tbl
and Rtibble
both in storage - SQL
tbl
and Rtibble
both in memory - SQL
tbl
in storage and Rtibble
in memory - SQL
tbl
in memory and Rtibble
in storage
- SQL
- Which SQL clause is used to extract data from a database?6
- OPEN
- EXTRACT
- SELECT
- GET
- With SQL, how to you retrieve a column named “FirstName” from a table named “Persons”?7
SELECT
Persons.FirstName- EXTRACT FIRSTNAME
FROM
Persons SELECT
FirstNameFROM
PersonsSELECT
“FirstName”FROM
“Persons”
- With SQL, how do you select all the columns from a table named “Persons”?8
SELECT
PersonsSELECT
*FROM
PersonsSELECT
[all]FROM
PersonsSELECT
*.Persons
- With SQL, how can you return the number of records in the “Persons” table?9
SELECT
COLUMNS(*)
FROM
PersonsSELECT
COUNT(*)
FROM
PersonsSELECT
NO(*)
FROM
PersonsSELECT
LEN(*)
FROM
Persons
- With SQL, how do you select all the records from a table named “Persons” where the value of the column “FirstName” is “Peter”?10
SELECT
*FROM
PersonsWHERE
FirstName <> ‘Peter’SELECT
*FROM
PersonsWHERE
FirstName = ‘Peter’SELECT
*FROM
PersonsWHERE
FirstName == ‘Peter’SELECT
[all]FROM
PersonsWHERE
FirstNameLIKE
‘Peter’SELECT
[all]FROM
PersonsWHERE
FirstName = ‘Peter’
- With SQL, how do you select all the records from a table named “Persons” where the “FirstName” is “Peter” and the “LastName” is “Jackson”?11
SELECT
FirstName = ‘Peter’, LastName = ‘Jackson’FROM
PersonsSELECT
*FROM
PersonsWHERE
FirstName <> ‘Peter’ AND LastName <> ‘Jackson’SELECT
*FROM
PersonsWHERE
FirstName = ‘Peter’ AND LastName = ‘Jackson’SELECT
*FROM
PersonsWHERE
FirstName == ‘Peter’ AND LastName == ‘Jackson’
- Which operator selects values within a range?12
BEWTEEN
WITHIN
RANGE
- With SQL, how do you select all the records from a table named “Persons” where the “LastName” is alphabetically between (and including) “Hansen” and “Pettersen”?13
SELECT
LastName > ‘Hansen’ AND LastName < ‘Pettersen’FROM
PersonsSELECT
*FROM
PersonsWHERE
LastName BETWEEN ‘Hansen’ AND ‘Pettersen’SELECT
*FROM
PersonsWHERE
LastName > ‘Hansen’ AND LastName < ‘Pettersen’
- Which SQL statement returns only different values?14
SELECT
UNIQUE
SELECT
DISTINCT
SELECT
DIFFERENT
- Which SQL keyword is used to sort the result-set?15
ORDER BY
ORDER
SORT
SORT BY
- With SQL, how can you return all the records from a table named “Persons” sorted descending by “FirstName”?16
SELECT
*FROM
PersonsORDER
FirstNameDESC
SELECT
*FROM
PersonsSORT
‘FirstName’DESC
SELECT
*FROM
PersonsORDER BY
FirstNameDESC
SELECT
*FROM
PersonsSORT BY
‘FirstName’DESC
- The OR operator displays a record if ANY conditions listed are true. The AND operator displays a record if ALL of the conditions listed are true.17
- TRUE
- FALSE
- In order to
SELECT
the records with foods that are either green or yellow fruit:18- …
WHERE
type = ‘fruit’ AND color = ‘yellow’ OR color = ‘green’
- …
WHERE
(type = ‘fruit’ AND color = ‘yellow’) OR color = ‘green’
- …
WHERE
type = ‘fruit’ AND (color = ‘yellow’ OR color = ‘green’)
- …
WHERE
type = ‘fruit’ AND color = ‘yellow’ AND color = ‘green’
- …
WHERE
type = ‘fruit’ AND (color = ‘yellow’ AND color = ‘green’)
- …
- What is the purpose of a
JOIN
?19- it filters the rows returned by the
SELECT
statement. - it specifies the columns to be retrieved.
- it combines rows from two or more tables based on a related column.
- it orders the results in ascending or descending order.
- it filters the rows returned by the
- What is the purpose of the
UNION
operator in SQL?20- it combines the results of two or more
SELECT
statements. - it performs a pattern match on a string.
- it retrieves the maximum value in a column.
- it filters the rows returned by the
SELECT
statement.
- it combines the results of two or more
- What is the purpose of the
INNER JOIN
in SQL?21- it retrieves the maximum value in a column.
- it combines rows from two or more tables based on a related column.
- it filters the rows returned by the
SELECT
statement. - it performs a pattern match on a string.
- What is the purpose of the
LEFT JOIN
in SQL?22- it combines rows from two or more tables based on a related column.
- it retrieves the maximum value in a column.
- it filters the rows returned by the
SELECT
statement. - it performs a pattern match on a string.
RIGHT JOIN
keeps all the rows in …?23- the first table.
- the second table.
- both tables.
- neither table
- Who is removed in a
RIGHT JOIN
?24- Mick
- John
- Paul
- Keith
- Which variable(s) are removed in a
RIGHT JOIN
?25- name
- band
- plays
- none of them
- In SQL, what happens to Mick’s “plays” variables in a
FULL JOIN
?26- Mick is removed
- guitar
- bass
- NA
NULL
grep("q[^u]", very.large.word.list)
would not match which of the following?27- Iraqi
- Iraqian
- Iraq
- zaqqun (tree that “springs out of the bottom of Hell”, in the Quran)
- Qantas (the Australian airline)
- Which of the following regex would match to both “grey” and “gray”?28
- “gr[ae]y”
- “gr(a|e)y”
- “gray | grey”
- “gr[a|e]y”
- some / all of the above – which ones?
- What will the result be for the following code?29
- 10
- 1
- 0
- NA
str_extract("My dog is 10 years old", "\\d")
- What will the result be for the following code?30
- 10
- 1
- 0
- NA
str_extract("My dog is 10 years old", "\\d+")
- What will the result be for the following code?31
- .
- Episode 2: The pie whisperer. (4 August 2015)
- Episode
- E
str_extract("Episode 2: The pie whisperer. (4 August 2015)", ".")
- What will the result be for the following code?32
- .
- Episode 2: The pie whisperer. (4 August 2015)
- Episode
- E
str_extract("Episode 2: The pie whisperer. (4 August 2015)", ".+")
- What will the result be for the following code?33
- .
- Episode 2: The pie whisperer. (4 August 2015)
- Episode
- E
str_extract("Episode 2: The pie whisperer. (4 August 2015)", "\\.")
- How can I pull out just the numerical information in $47?34
- “(?<=\$)\d”
- “(?<=\$)\d+”
- “\d(?=\$)”
- “\d+(?=\$)”
- You want to know all the types of pies in the text strings. They are written as, for example “apple pie”.35
- “\w+(?!pie)”
- “\w+(?! pie)”
- “\w+(?=pie)”
- “\w+(?= pie)”
str_extract(c("apple pie", "chocolate pie", "peach pie"), "\\w+(?= pie)")
[1] "apple" "chocolate" "peach"
str_extract(c("apple pie", "chocolate pie", "peach pie"), "\\w+(?=pie)")
[1] NA NA NA
- We say that lookarounds are “zero-lenghth assertions”. What does that mean?36
- we return the string in the lookaround
- we replace the string in the lookaround
- we return the string at the lookaround
- we replace the string at the lookaround
- With SQL, how do you select all the records from a table named “Persons” where the value of the column “FirstName” starts with an “a”?37
SELECT
*FROM
PersonsWHERE
FirstName = ’a.*’SELECT
*FROM
PersonsWHERE
FirstName = ’a*’SELECT
*FROM
PersonsWHERE
FirstNameREGEXP
’a.*’SELECT
*FROM
PersonsWHERE
FirstNameREGEXP
’a*’SELECT
*FROM
PersonsWHERE
FirstNameREGEXP
’(?i)a.*’
- What is the main way to absolutely recognize a record within a database?38
- Foreign key
- Primary key
- Unique key
- Natural key
- Alternate key
- What does a foreign key do?39
- Directly identifies another table
- Directly identifies another column
- Gives access to another entire database
- Translates the database into another language
- Which of these would likely be used as a foreign key between a table on student enrollment and student grades?40
- grades
- tuition
- student_name
- student_hometown
- For the student records (for two tables: enrollment and grades), which is the most likely combination?41
- name as primary key to both
- name as foreign to both
- name as primary in enrollment and foreign in grades
- name as foreign in enrollment and primary in grades
- Which SQL statement is used to create a database table called ‘Customers’?42
CREATE DATABASE TAB
CustomersCREATE DATABASE
CustomersCREATE DATABASE TABLE
CustomersCREATE TABLE
CustomersCREATE DB
Customers
- Which SQL statement revises data in a database?43
SAVE AS
MODIFY
SAVE
UPDATE
- Which SQL statement takes out data from a database?44
REMOVE
DELETE
COLLAPSE
- The
NOT NULL
constraint enforces a column to not acceptNULL
values.45- FALSE
- TRUE
- Which SQL statement places new data in a database?46
ADD RECORD
INSERT INTO
ADD NEW
INSERT NEW
- With SQL, how can you insert a new record into the “Persons” table?47
INSERT
INTO
Persons VALUES (‘Jimmy’, ‘Jackson’)INSERT
(‘Jimmy’, ‘Jacskon’)INTO
PersonsINSERT
VALUES (‘Jimmy’, ‘Jackson’)INTO
Persons
- With SQL, how can you insert “Olsen” as the “LastName” in the “Persons” table?48
INSERT
INTO
Persons (LastName) VALUES (‘Olsen’)INSERT
INTO
Persons (’Olsen)INTO
LastNameINSERT
(‘Olsen’)INTO
Persons (LastName)
- How can you change “Hansen” into “Nilsen” in the “LastName” column in the Persons table?49
MODIFY
PersonsSET
LastName=‘Nilsen’WHERE
LastName=‘Hansen’UPDATE
PersonsSET
LastName=‘Hansen’INTO
LastName=‘Nilsen’MODIFY
PersonsSET
LastName=‘Hansen’INTO
LastName=‘Nilsen’UPDATE
PersonsSET
LastName=‘Nilsen’WHERE
LastName=‘Hansen’
- With SQL, how can you delete the records where the “FirstName” is “Peter” in the Persons Table?50
DELETE
FROM
PersonsWHERE
FirstName=‘Peter’DELETE
FirstName=‘Peter’FROM
PersonsDELETE ROW
FirstName=‘Peter’FROM
Persons
- In the
flights
table, the followingINDEX
es exist:Tailnum
,Year
, andDate
. How many rows would be looked through if theWHERE
filter was onmonth
only?51- more than 6.3 million
- less than 6.3 million
- more than 700,000
- less than 700,000
- Which has a larger cardinality,
Tailnum
orYear
?52Tailnum
Year
- they have the same cardinality
- neither has a cardinality
- Which index takes up more storage space, the one on
Tailnum
or the one onYear
?53Tailnum
Year
- they take up the same space
- you can’t index on either variable
- Which index is more effective at reducing querying time, the one on
Tailnum
or the one onYear
?54Tailnum
Year
- the queries would be the same
- you can’t query on either variable
- What does the R function
ifelse(a, b, c)
do?55- a = TRUE option, b = FALSE option, c = question
- a = FALSE option, b = TRUE option, c = question
- a = question, b = TRUE option, c = FALSE option
- a = question, b = FALSE option, c = TRUE option
- What does the R function
case_when()
do?56- renames a variable
- changes the data type of a variable
- partitions a numeric variable
- creates a new variable by re-coding an original variable
- What does the R function
cut()
do?57- renames a variable
- changes the data type of a variable
- partitions a numeric variable
- creates a new variable by re-coding an original variable
Footnotes
- A relational database management system.
- The first versions were created in the 1970s and called SEQUEL (Structured English QUEry Language). c. SQL came about in particular systems in the 1980s.
- relational database management systems.
- computer’s hard drive / storage
- SQL
tbl
in storage and Rtibble
in memory
- SQL
- SELECT
SELECT
FirstNameFROM
Persons
SELECT
*FROM
Persons
SELECT
COUNT(*)
FROM
Persons
SELECT
*FROM
PersonsWHERE
FirstName = ‘Peter’ (d. would also work.)
SELECT
*FROM
PersonsWHERE
FirstName = ‘Peter’ AND LastName = ‘Jackson’
BEWTEEN
SELECT
*FROM
PersonsWHERE
LastName BETWEEN ‘Hansen’ AND ‘Pettersen’
SELECT
DISTINCT
ORDER BY
SELECT
*FROM
Persons ORDER BY FirstName DESC
- TRUE
- …
WHERE
type = ‘fruit’ AND (color = ‘yellow’ OR color = ‘green’)
- …
- it combines rows from two or more tables based on a related column.
- it combines the results of two or more
SELECT
statements.
- it combines the results of two or more
- it combines rows from two or more tables based on a related column.
- it combines rows from two or more tables based on a related column.
- the first table
- Mick
- none of them (all variables are kept in all joins)
NULL
(it would be NA in R)
neither c. nor e. would match. Inside the bracket “[^u]” matches anything other than a “u”, but it has to match something.↩︎
- all of the above. Inside a character class
|
is a normal character and would therefore match “grey” and “gray” and “gr|y”. Which is not what we want, but would work to match both “grey” and “gray”.
- all of the above. Inside a character class
- 1 (because
\d
matches only a single digit).
- 1 (because
- 10 (because
\d+
matches at least one digit).
- 10 (because
- E (because
.
matches anything, and returns only a single character).
- E (because
- Episode 2: The pie whisperer. (4 August 2015) (because
.
matches anything, and with the+
it returns multiple characters).
- Episode 2: The pie whisperer. (4 August 2015) (because
- . (because
\.
matches the period, .).
- . (because
- “(?<=\$)\d+”
- “\w+(?= pie)”
- we return the string at the lookaround
SELECT
*FROM
PersonsWHERE
FirstNameREGEXP
’(?i)a.*’ (n.b., theLIKE
function will give you a similar result, with%
as a wildcard: SELECT*
FROMPersons
WHERE` FirstName LIKE ‘a%’)
- Primary key
- Directly identifies another column
- student_name
- name as primary in enrollment and foreign in grades (the primary key must uniquely identify the records, and name is unlikely to do that in a grades database.)
CREATE TABLE
Customers
UPDATE
DELETE
- TRUE
INSERT INTO
INSERT
INTO
Persons VALUES (‘Jimmy’, ‘Jackson’)
INSERT
INTO
Persons (LastName) VALUES (‘Olsen’)
UPDATE
PersonsSET
LastName=‘Nilsen’WHERE
LastName=‘Hansen’
DELETE
FROM
PersonsWHERE
FirstName=‘Peter’
- more than 6.3 million. Because there is no index on month (and we don’t have a year to incorporate month into the Date index), we need to look through all 48 million rows.
Tailnum
. The cardinality is the number of unique values, and there are many more unique planes than years.
Tailnum
. Because the cardinality is higher, it will take up much more space in the index.
Tailnum
. Because the index is more complete, it will make the querying more efficient.
- a = question, b = TRUE option, c = FALSE option
- creates a new variable by re-coding an original variable
- partitions a numeric variable