For the purposes of our lab we will use the sqlite3 . In the lab we use windows. For Mac OS and Linux, you can dowload binaries here.
But before that:
These were non-SQL commands. Remember that SQL command ends with a semi-colon ";" Detailed Online Documentation can be found at: http://www.sqlite.org/sqlite.html 2. A List of the Tables in our Database
3. Selection Queries 1. Retrieving whole table A query result is always in the form of the table. Try the following query:
2. Retrieve specific columns If you only need some of the attributes, you should specify them after SELECT. For example below query retrieves credit_status column of Enrolled table.
Exercise 1: List the names of all classrooms and their capacities. 3. Retrieve specific rows. Write a query for retrieving all students major in comp sci. Now we should use WHERE clause in order to specify the property of rows, which we want to retrieve.
Exercise 2: Write a query listing the ID of the room that course CS 105 is taught. 4. Logical Operators. Try the following query:
What does this query do? Try the following query:
What does this query do? Exercise 3: Write a query listing the IDs of the rooms that are not in CAS building. 5. Aggregate queries Now try the following query:
What does this query do? Exercise 4: Write a query that calculates the average, the sum, the min and the max capacity of the rooms. 6. Subqueries The following query lists the names of the students who do not major in comp sci:
Would this query give us the same results?
7. More complex queries Exercise 5: Write a query listing all the rooms in CAS that their capacity is 50 seats below the average of all the rooms or more ( capacity >= avg - 50 ). Exercise 6: Write a query that returns the list of the departments and the number of students that major in each department. |
|||||||||||