Display the COUNT of rows in each of the tables: Grade_report, Student, and Section. How many rows would you expect in the Cartesian product of all three tables? Display the COUNT (not the resulting rows) of the Cartesian product of all three and verify your result. Use SELECT COUNT(*) ... Cartesian Product of all three tables: grade_report * student * section Display the COUNT of section-ids f
...[Show More]
Display the COUNT of rows in each of the tables: Grade_report, Student, and Section. How many rows would you expect in the Cartesian product of all three tables? Display the COUNT (not the resulting rows) of the Cartesian product of all three and verify your result. Use SELECT COUNT(*) ...
Cartesian Product of all three tables:
grade_report * student * section
Display the COUNT of section-ids from the Section table, and then the COUNT of DISTINCT section-ids from the Grade_report table. What does this information tell you? Hint: section_id is the primary key of the Section table.
The Cartesian is highest number count for each table multiplied with other table. For section row count would be 32 and Grade_report would be 209.
Get the statement to work as a COUNT of a join of the three tables, Student, Grade_report, 105 and Section. Use table aliases in the join condition (remember to use /* join conditions */). Note that a join of n tables requires (n-1) join conditions, so here you have to have two join conditions—one to join the Student and Grade_report tables, and one to join the Grade_report and Section tables. Note the number of rows that you get (expect no more rows than is in the Grade_report table.) Why?
Modify the query and put the accounting (ACCT) condition in the WHERE clause. Note the number of rows in the result—it should be a good bit less than in (a).
COUNT(*)
Again, modify the query and add the grade constraints. The number of rows should decrease again. Note that if you have WHERE x and y or z, parentheses are optional, but then the criteria will be interpreted according to precedence rules.
How many students have names like “SMITH” or “Smith”?
How many have names that contain the letter sequence “SMITH”?
How many student names end in “LD”?
Would “SELECT * FROM Student WHERE sname LIKE ‘SMITH%’” find someone whose name was:
(i) “LA SMITH”
(ii) “SMITH-JONES”
(iii) “SMITH JR.”
(iv) “SMITH, JR”
no rows selected
Answer: No.
Would you call UPPER or LOWER an aggregate function? Why or why not?
Yes because the queries would produce the same result. –
Pad all the student names in the Student table with ... on the right.
List the junior level COSC courses (like COSC3xxx) and the name of the course. Use the Course table.
Using the COUNT feature, determine whether there are duplicate names or student numbers in the Student table.
Assume that all math courses start with MATH. How many math courses are there in the Section table? From the COUNT of courses, does it appear that there are any math courses in the Section table that are not in the Course table? Again, using COUNTs, are there any math courses in the Course table that are not in the Section table? Does it appear that there are any courses at all that are in the Grade_report, Section, or Course tables that are not in the others? (We will study how to ask these questions in SQL in a later chapter). Note that a query like the following would not work:
SELECT g.section_id FROM Grade_report g, Section t WHERE g.section_id <> t.section_id;
Explain why WHERE .. <> .. will not work to produce the desired output.
Display dictionary views for the tables we have in the Student-Course database (refer to the diagram in Appendix 3 for all the table names). Use “all_tables” as the dictionary view. Do the query as follows:
DESCRIBE the table with DESC all_tables;
Display the number of rows in all_tables. Use SELECT COUNT(*) FROM all_tables;
Observe that when you are exploring the dictionary, it is not a good idea to simply SELECT * FROM whatever, where whatever is some dictionary view. Dictionary views are often long and wide—wide in that there are often many attributes and many of those attributes are not necessarily interesting.
SQL> SELECT COUNT(*) FROM ALL_TABLES;
Display the owner and table_name from all_tables where owner = ‘your userid’.
Display the first two rows (use WHERE rownum < 3) of the all_tables table.
MAX_TRANS INITIAL_EXTENT NEXT_EXTENT MIN_EXTENTS MAX_EXTENTS PCT_INCREASE FREELISTS FREELIST_GROUPS LOGGING BAC NUM_ROWS BLOCKS EMPTY_BLOCKS
AVG_SPACE CHAIN_CNT AVG_ROW_LEN AVG_SPACE_FREELIST_BLOCKS NUM_FREELIST_BLOCKS DEGREE INSTANCES
CACHE TABLE_LOCK SAMPLE_SIZE LAST_ANALYZED PARTITION IOT_TYPE TEM SEC NESTED
BUFFER_POOL FLASH_CACHE CELL_FLASH_CACHE ROW_MOVEMENT GLOBAL_ST USER_STAT
COMPRESS_FOR DROPPED READ_ONLY SEGMENT_C RESULT_CACHE
For Room, Course, Prereq, Department_to_major, list the attributes, number of rows, number of distinct rows, and number of rows without nulls. As you gather the information, put the information in a tabular format, as shown below (note – you may want to create this table in your word processor as you gather the information):
all the tables in the Student-Course database – Student, Grade_report, Section,
Table
Student
Section
Attribute
stno sname major class section_id
Rows without Nulls
48 48 3 etc.
Rows Distinct Rows
48 48 47
8 etc.
etc.
Also, note that there is probably no “one” query that will give you this information. You will have to find this information using separate queries, and then put the information together in a tabular format.
Hint: you can use:
SELECT COUNT (*)
FROM Student
WHERE sname IS NULL
Find the count, sum, average, minimum, and maximum capacity of rooms in the database
(hint: Use the Room table for this question).
SQL> SELECT COUNT(CAPACITY), SUM(CAPACITY), AVG(CAPACITY), MIN(CAPACITY), MAX(CAPACITY)
2 FROM rearp.room;
COUNT(CAPACITY) SUM(CAPACITY) AVG(CAPACITY) MIN(CAPACITY) MAX(CAPACITY)
--------------- ------------- ------------- ------------- -------------
Where there is a null value for the capacity, assume the capacity to be 40, and find the average room size again.
In Chapter 2, we introduced some date functions, namely ADD_MONTHS and MONTHS_ BETWEEN. Use the MONTHS_BETWEEN and other appropriate functions to write one query that returns the number of years between the oldest and youngest student in the Student table.
[Show Less]