Chapter 07 Introduction to Structured Query Language (SQL)

  1. A database language enables the user to perform complex queries designed to transform the raw data into useful information.

True

2.  A(n) asterisk character is a symbol that can be used as a general substitute for other characters or commands.

False

3.  The COUNT function is designed to tally the number of non-null “values” of an attribute and is often used in conjunction with the DISTINCT clause.

True 

4.  The SQL COUNT function gives the number of rows containing non-null values for a given column.

True

5.  Rows can be grouped into smaller collections quickly and easily using the COUNT clause within the SELECT statement.

False

6.  All SQL commands must be issued on a single line.

False 

7.  Although SQL commands can be grouped together on a single line, complex command sequences are best shown on separate lines, with space between the SQL command and the command’s components.

True 

8.  You can select partial table contents by naming the desired fields and by placing restrictions on the rows to be included in the output.

True 

9.  Oracle users can use the Access QBE (query by example) query generator.

False 

10.  Comparison operators cannot be used to place restrictions on character-based attributes.

False 

11. When building your clauses which of the following is recommended to address first:

FROM

12. In practice which of the following is more common to find?

 Cryptic, confusing and nonstandardized attribute names.

13. Which of the following is a valid reason to not include the DISTINCT clause if it is not necessary?

Improve the performance

14. What command should be used to save permanently all changes made to a database.

COMMIT

15. Which of the following queries correctly uses an alias for the MRENT field?

SELECT ID, MRENT AS “monthly rent” FROM TENANTS

16. Which of the following is true about the result of the following query?

It has three columns of the CLIENT table.

17. Consider the following table

Table name: TENANT
| ID | NAME | RENT |
| 18 | Alex | 219 |
| 31 | Rose | 250 |
| 51 | Alex | 300 |
| 77 | Mary | 280 |
| 81 | Rose | 240 |

How many rows are in the following query?

SELECT DISTINCT NAME FROM TENANT.

 3

18. Consider the following table

Table name: TENANT
| ID | NAME | RENT |
| 18 | Alex | 219 |
| 31 | Rose | 250 |
| 77 | Alex | 300 |
| 41 | Mary | 280 |
| 81 | Rose | 240 |

Which query returns the following?

| ID | NAME | RENT |
| 18 | Alex | 219 |
| 81 | Rose | 240 |
| 31 | Rose | 250 |
| 41 | Mary | 280 |
| 77 | Alex | 300 |

SELECT * FROM TENANT ORDER BY RENT

19.After requesting a service, a client must pay 30 days after the service is required. In the SERVICE table, there exists the attribute DATE that holds the day a service was required, but there is no attribute for the due date. Which of the following queries shows the date a service was required and when the payment is due as DUE_DATE.

SELECT SID, DATE, DUE+30 AS DUE DATE FROM SERVICE

20. The table STUDENT has the attributes STUDENT_ID, NAME, SCHOOL_ID, and ADDR. The table SCHOOL has the attributes SCHOOL_ID, NAME, and STATE_CODE. Assume that there is a 1:N relation between SCHOOL and STUDENT. Which of the following creates a table that shows the STUDENT attributes and the corresponding SCHOOL attributes?

SELECT * SCHOOL_ID FROM STUDENT JOIN SCHOOL USING(SCHOOL_ID)

21. The table STUDENT has the attributes STUDENT_ID, NAME, S_ID, and ADDR. The table SCHOOL has the attributes SCHOOL_ID, NAME, and STATE_CODE. Assume that there is a 1:N relation between SCHOOL and STUDENT where the common attributes are S_ID, and SCHOOL_ID. Which of the following creates a table that shows the STUDENT attributes and the corresponding SCHOOL attributes?

SELECT * FROM STUDENT JOIN SCHOOL ON STUDENT.S_ID = SCHOOL.SCHOOL_ID

22. Consider the following tables

Name: CLIENTS

Primary Key: CLIENT_ID

CLIENT_IDNAME
19283Jhon
19281Mary
19272Elizabeth

Name: SALES

Primary Key: (SALE_ID, PROD_ID)

Foreign Key: PROD_ID, CLIENT_ID

SALE_IDPROD_IDCLIENT_IDDATE
FGS1230112930182192812022-07-10
DEF2835819283104192722022-07-11
GHM392019283123179132021-06-22

How many rows produces the following query?

SELECT *

FROM CLIENTS RIGHT JOIN SALES ON CLIENTS.CLIENT_ID = SALES.CLIENT_ID

 3

23. Which of the following better describes the result of SELECT * FROM table1 LEFT JOIN table2 ON table1.id = table2.id2?

Rows match the join condition and rows in table1 with unmatched id on table2.

24. When using a cross join between a table with 8 rows and another with 5 rows how many rows are in the result?

40

25. Which of the following is equivalent to WHERE attribute BETWEEN 10 AND 1000?

WHERE attribute >= 10 AND attribute <= 1000

26. Which comparison operator indicates a value is not equal?

<>

27. Which of the following is a match for “%c%s” when using the LIKE operator?

 “acts”

28. Which of the following are equivalent to WHERE attribute IN (123, 200)?

WHERE attribute = 123 OR attribute = 200

29. Which of the following is equivalent to WHERE attribute NOT BETWEEN 100 AND 1000?

WHERE attribute < 100 OR attribute > 1000

30. Which of the following is equivalent to WHERE NOT(attribute1 > 100 AND attribute2 = 100)?

WHERE attribute1 <= 100 AND attribute2 <> 100

31. The special operator used to check whether a subquery returns any rows is _____.

EXISTS

32. Consider the following tables:

table1

vcodename
7Alex
8Tony
9Charles
11Mary

table2

scodevcodetotal
3417102
213959
312789
7123301

How many rows has the result of the following query?

SELECT * FROM table1 NATURAL JOIN table2

​  3

33. Consider the following tables:

vcodename
7Alex
8Tony
9Charles
11Mary

table2

scodevcodercode
34197
213114
31278

How many rows has the result of the following query?

SELECT * FROM table1 JOIN table2 ON table1.vcode = table2.rcode

​1

34. Consider the following tables:

vcodename
7Alex
8Tony
9Charles
11Mary
13Jhon

table2

scodevcodercode
34197
213114
31278

How many rows has the result of the following query?

SELECT * FROM table1 LEFT JOIN table2 ON table1.vcode = table2.vcode


5

35. Suppose that a mattress store has a TABLE1 with sales representatives with an attribute vcode as primary key. It also has a TABLE2 with every mattress sold, the table has an attribute vcode to indicate which sales representative made the sale, and a mt_code to indicate which mattress was sold. Which of the following returns all the sales representatives that haven’t closed a sale?

SELECT * FROM TABLE1 RIGHT JOIN TABLE2 ON TABLE1.vcode = TABLE2.vcode WHERE mt_code IS NULL.

36. Some rows of a User table are shown below:

User

ucodenamerankingrate
7Alex30.2
8Tony20.3
9Charles10.8
11Mary30.7

Which of the following queries retrieves the rows where the ranking is less than 3 and the rate is greater than 0.4.

SELECT * FROM User WHERE ranking < 3 AND rate > 0.4

37. Some rows of a User table are shown below:

User

ucodenamephonescode
7Alex847 – 3902UX
8Tony203 – 3902PX
9CharlesBD
11Mary877 – 3333BD

Which of the following queries retrieves the rows where there is no phone?

​SELECT * FROM User WHERE phone IS NULL

38.  In a car rental table VEHICLES, the YEAR attribute indicates the YEAR a car was bought, and the BIN attribute a unique identification number for a car. What describes better the result of the query below?

SELECT BIN, YEAR FROM VEHICLES WHERE YEAR IN (2010, 2020)

All BINs, and YEARS of vehicles that were bought in 2010, or 2020

39. Below are some rows of the PROVIDERS table for a factory:

PCODENAMEPHONE
10192Hans, Inc.229 – 3092
98411Tools and More293 – 1029
0489035Motors Inc.993 – 1821

You desire to get all providers that are legal corporations. Legal corporations must include the Inc in their name. Which of the following queries provides the desired result.

​SELECT PCODE, NAME FROM PROVIDERS WHERE NAME LIKE ‘%Inc%’

40. Below are some rows of the PROVIDERS table for a factory:

PCODENAMEPHONE
10192Hans, Inc.231 – 3092
98411Tools and More231 – 1029
0489035Motors Inc.993 – 1821

All providers from the factory zone of the city start with 231. You want to get the providers that are in the factory zone of the city. Which of the following is more appropriate?

SELECT * FROM PROVIDERS WHERE PHONE LIKE ‘231%’

41. Consider the following table:

TABLE1

val1val2val3
312910
239130
128930
512920
901210
121020

What is the result of the query below?

SELECT * FROM TABLE1 WHERE val2 BETWEEN         (100, 400) AND val3 IN (10, 20)

val1val2val3
312910
512920

42. If you want to count how many students got a gpa higher than 3.0 from the STUDENT table. Which of the following is more appropriate? Assume that the GPA attribute of the table stores the gpa of each student.

SELECT COUNT(GPA) FROM STUDENT WHERE GPA > 3.0

43. Consider the STUDENT table given below:

CODENAMEGPAYEAR
291ALEX3.12
938MICHELE2.31
931JHON3.31
182JOE3.42
190REY2.02
330RON3.93

What is the result from the query below?

SELECT MAX(GPA) FROM STUDENT WHERE STUDENT.YEAR = 2

3.4

44. Consider the STUDENT table given below:

CODENAMEGPAYEAR
291ALEX3.12
938MICHELE2.31
931JHON3.31
182JOE3.42
190REY2.02
330RON3.93

How many rows are returned from the query below?

SELECT MAX(GPA) FROM STUDENTS GROUP BY YEAR

Assume that if an error occurs 0 rows are returned.

 3

45. Consider the STUDENT table given below:

CODENAMEGPAYEAR
291ALEX3.12
938MICHELE2.31
931JHON3.31
182JOE3.42
190REY2.02
330RON3.93

Which of the following queries retrieve a table with the max GPA of each year sorted by the max GPA value.

SELECT YEAR, MAX(GPA) FROM STUDENT GROUP BY YEAR ORDER BY MAX(GPA)

46. Some rows of the STUDENT table are shown below:

CODENAMEGPAYEAR
291ALEX3.12
938MICHELE2.31
931JHON3.31
182JOE3.42
190REY2.02
330RON3.93

Which best describes the result of the query below?

SELECT YEAR, AVG(GPA) FROM STUDENT WHERE GPA > 2.0 GROUP BY YEAR

The average GPA of students with a GPA higher than 2.0 each year.

47. Some rows of the STUGRADE table of a school are shown below:

STU_CODECLS_CODEGRADEYEAR
2911113.12010
938101B2.32011
931M1013.32040
291M1013.42018
1901112.02021
9313213.92003

Suppose that STU_CODE is the student code (foreign key) and CLS_CODE is the class code (foreign key). Which of the following computes the average for each year of the student with code 931?

SELECT AVG(GRADE) FROM STUGRADE WHERE STU_CODE = 931 GROUP BY YEAR

48. Some rows of the STUGRADE table of a school are shown below:

STU_CODECLS_CODEGRADEYEAR
2911113.12010
938101B2.32011
931M1013.32040
291M1013.42018
1901112.02021
9313213.92003

You want to show all STU_CODE with average grades higher than 3.0. Which of the following gets the required data?

SELECT STU_CODE, AVG(GRADE) FROM STUGRADE GROUP BY STU_CODE HAVING AVG(GRADE) > 3.0

49. Which of the following differentiates the HAVING clause from the WHERE clause?

WHERE is executed prior to GROUP BY and HAVING after.

50. Some rows of the STUDENT table are given below:

CODENAMEDEPARTMENTGPAYEAR
291ALEXPSI3.11992
938MICHELEPHY2.31992
931JHONMD3.32001
182JOEMD3.42002
190REYPHY2.02001
330RONPSI3.92001

You want to get a list of the maximum GPA of each department with an average GPA of 2.4, but only for students after 2004. Which of the following gets the desired result?

SELECT MAX(GPA) FROM STUDENT WHERE YEAR > 2004 GROUP BY DEPARTMENT HAVING AVG(GPA) > 2.4

51. Some of the rows the GRADES table are below:

CODENAMEGPAYEAR
938ALEX3.12
931MICHELLE2.31
182JOE3.13
918ADELE2.92

Which of the following queries returns the name of all the students that achieved the maximum GPA among all the students?

SELECT NAME FROM STUDENT

WHERE GPA = (SELECT MAX(GPA) FROM STUDENT)

52. Some rows of the tables SALESPERSON and SALES are shown below:

SALESPERSON

VCODENAME
7Alex
8Tony
9Charles
11Mary

SALES

SCODEVCODETOTAL
341919.50
2131189.95
312731.10

Which of the following queries return the salespersons codes with at least one sale greater than the average?

SELECT VCODE FROM SALES

WHERE TOTAL > (SELECT AVG(TOTAL) FROM SALES);

53. Some rows of the tables SALESPERSON and SALES are shown below:

SALESPERSON

VCODENAME
7Alex
8Tony
9Charles
11Mary

SALES

SCODEVCODETOTAL
341919.50
2131189.95
312731.10

You want the name of all the salespersons that have made at least one sale with a total higher than 100.

Which of the following queries gives the desired result?

SELECT NAME FROM SALESPERSON

WHERE VCODE IN (SELECT VCODE FROM SALES WHERE TOTAL > 100)

54. Some rows of the table STUDENT are shown below:

CODENAMEDEPARTMENTGPAYEAR
291ALEXPSI3.11992
938MICHELEPHY2.31992
931JHONMD3.32001
182JOEMD3.42002
190REYPHY2.02001
330RONPSI3.92001

You want the name all departments that have a department GPA average of 2004 greater than the global GPA average. Which query gives you the desired result?

SELECT DEPARTMENT

WHERE YEAR = 2004

FROM STUDENT

GROUP BY DEPARTMENT

HAVING AVG(GPA) > (SELECT AVG(GPA) FROM STUDENT);

55. Some rows of the table STUDENT are shown below:

CODENAMEDEPARTMENTGPAYEAR
291ALEXPSI3.11992
938MICHELEPHY2.31992
931JHONMD3.32001
182JOEMD3.42002
190REYPHY2.02001
330RONPSI3.92001

Which of the following queries return the students from the MD department with a GPA greater than the global average in 2004?

SELECT NAME, GPA

FROM STUDENT

GROUP BY DEPARTMENT

HAVING GPA > (SELECT AVG(GPA) FROM STUDENT WHERE YEAR = 2004);

56. Some rows of the table STUDENT are shown below:

CODENAMEDEPARTMENTGPAYEAR
291ALEXPSI3.11992
938MICHELEPHY2.31992
931JHONMD3.32001
182JOEMD3.42002
190REYPHY2.02001
330RONPSI3.92001

You want to get the name of the students that are in a department with a department GPA average larger than 2.5. Which query produces the desired result?

SELECT NAME

FROM STUDENT

WHERE DEPARTMENT IN

 (SELECT DEPARTMENT

 FROM STUDENT

 GROUP BY DEPARTMENT

 HAVING AVG(GPA) > 2.5);

57. In subquery terminology, the first query in the SQL statement is known as the _____ query.

outer

58. Consider the following table:

Name: table1

cod1val1val2
10108
12106
211115
33102
41911
8106
1495
11114

What is the result of the query below?

SELECT *

FROM table1

WHERE val2 > all(

 SELECT val2

 FROM table1

 WHERE val1 = 10);

cod1val1val2
211115
41911

59. The _____ function returns the current system date in MS Access.

DATE()

60. When using the Oracle TO_DATE function, the code _____ represents a three-letter month name.

MON

61. Consider the following table:

Name: table1

cod1val1val2
10108
12106
211115
33102
41911
8106
1495
11114

What is the result of the query below?

SELECT *

FROM table1

WHERE val1 IN (SELECT val1

 FROM table1

 WHERE val2 = (SELECT MAX(val2)

 FROM table1));

cod1val1val2
211115
11114

62. Consider the following tables:

Name: table1

cod1val1val2
10108
12106
211115
33102
41911
8106
1495
11114

What is the result of the query below?

SELECT MIN(cod1)

FROM (SELECT val1, MAX(val2) max_val2

 FROM table1

 GROUP BY val1) max_table

 JOIN table1

 ON max_table.val1 = table1.val1

WHERE val2 = max_val2;

10

63. Consider the following table:

Name: table1

cod1val1val2
10108
12106
211115
33102
41911
8106
1495
11114

What is the result of the query below?

SELECT MAX(val2)

FROM table1

WHERE val1 in (SELECT val1

 FROM table1

 WHERE val2 = (SELECT MIN(val2)

 FROM table1))

8

64. Some rows of the tables SALESPERSON and SALES are shown below.

SALESPERSON

VCODENAME
7Alex
8Tony
9Charles
11Mary

SALES

SCODEVCODETOTAL
341919.50
2131189.95
312731.10

Which of the following best describes the result of the following query?

SELECT NAME

FROM SALESPERSON

WHERE VCODE IN (SELECT VCODE

 FROM SALES

 WHERE TOTAL = (SELECT MAX(TOTAL)

 FROM SALES))

The name of the salespersons with a sale equal to the maximum TOTAL.

65. Consider the following table:

Name: table1

cod1val1val2
10108
12106
211115
33102
41911
8106
1495
11114

What is the result of the query below?

SELECT cod1, (SELECT MAX(val2) FROM table1) AS MAX2

FROM table1

WHERE val2 = MAX2 AND val1 = 10

cod1DIFF
1021
129
3313
89

66. Consider a table EMPLOYEES with an attribute HIRING_DATE that holds the date where an employee was hired as a date data type. Which of the following queries display the employees hired before 2019?

SELECT *

FROM EMPLOYEE

WHERE YEAR(HIRING_DATE) < 2019

67. The table STUDENTS has an attribute BIRTH_DATE that holds the birth date of a student in a date format. Which of the following gives the birthday of a student?

TO_DATE(BIRTH_DATE, ‘%M-%D’)

68. What is the result of SUBSTR(‘19425127’, 2, 4)?

‘9425’

69. Below are some rows of the table INVOICE

CODPROV_CODDATETYPELOCTOTAL
29101922022-03-1190TX1928
93013842022-05-0390NY2800

Overdue invoices are those whose date plus TYPE days have passed. Which of the following shows all invoices with overdue dates?

SELECT *

FROM INVOICE

WHERE DATE+TYPE > CURDATE()

70. While designing a query you determine that the data needs to be preprocessed. Which of the following is most appropriate?

Use a subquery to preprocess.

Other Links:

Statistics Quiz

Networking Quiz

See other websites for quiz:

Check on QUIZLET

Check on CHEGG




 

Leave a Reply

Your email address will not be published. Required fields are marked *