Concept explainers
“SELECT” command:
The “SELECT” command is used to retrieve data in a
Syntax for selecting values from the table is as follows:
SELECT STUDENT_ID FROM STUDENT;
- The given query is used to display each student ID from “STUDENT” table.
“COUNT” function:
- It is the one function of aggregate function.
- The “COUNT” function is used to compute the number of rows in a table.
Example:
The example for “COUNT” function is given below:
SELECT COUNT(*) FROM STUDENT WHERE MARK_CREDIT >= 90;
The above query is used to display the number of students whose mark credit is greater or equal to “90” by using “COUNT” function.
- From the given query, the asterisk (*) represent any column.
- User can also count the number of rows in a query by selecting a particular column instead of using the asterisk.
- The below example is as follows
SELECT COUNT(STUDENT_ID) FROM STUDENT WHERE MARK_CREDIT >= 90;
- The below example is as follows
“ORDER BY” Clause:
- User can sort the data in specific order using “ORDER BY” clause.
- The column on which to sort data is called a sort key or a simple key.
- To sort the output, use an “ORDER BY” clause followed by the sort key.
- If the user does not indicate a sort order, the output displayed in default order that is ascending order.
Example:
The example for “ORDER BY” clause is given below:
SELECT STUDENT_ID, STUDENT_NAME, STUDENT_CREDIT FROM STUDENT ORDER BY STUDENT_CREDIT;
The above query is used to list student ID, name and credit for each student with ascending order of student credit using an “ORDER BY” clause.
- From the given query, the sort key is “STUDENT_CREDIT”. So, the rows are sorted in ascending order by “STUDENT_CREDIT”.
“GROUP BY” Clause:
- User can group the data using “GROUP BY” clause.
- This clause allows the user to group data on a specific column and then computes statistics when user preferred.
Example:
The example for “GROUP BY” clause is given below:
SELECT CUSTOMER_NAME, SUM(AMOUNT) FROM CUSTOMERS GROUP BY CUSTOMER_NAME;
The above query is used to list the customer name and the sum of amount using “GROUP BY” clause.
Trending nowThis is a popular solution!
Chapter 4 Solutions
A Guide to SQL
- Classify students according to the total number of hours they have completed. (Less than30=freshman, 30 to 59 is sophomore, 60 to 89 is junior, 90+ senior)arrow_forwardWhich books aren't in the Fitness category? List each book title and category.arrow_forwardDetermine the sorts of books that are presently available in the inventory. Only one of each category should be included.arrow_forward
- 1. Write a database description for each of the relations shown, using SQL DDL (shorten, abbreviate, or change any data names, as needed for your SQL version). Assume the following attribute data types: StudentID (integer, primary key) StudentName (25 characters) FacultylD (integer, primary key) FacultyName (25 characters) CourselD (8 characters, primary key)arrow_forwardIf every student at a school is assigned a 4-digit person ID number, but 0 and 1 are not used in ID numbers and the numbers 8 and 9 are reserved for faculty, how many potential student ID numbers are there?arrow_forwardQUESTION 4 Convert the following ER diagram into a relational database schema, be certain to indicate primary keys and referential integrity constraints. Accident Driver reportNUM driverlD PK PK location Address accidentDate Name havearrow_forward
- What is the price of the least expensive item in the database?arrow_forwardShow students’ first name and last name, the course numbers the student took (don’t include currently taking) and its credits, and the grades of the courses in the ascending order of last name and first name and descending order of course number STUDENT TABLE 100001 Johnson Ariel 2000-07-10 Y 100002 Green Robin 2001-11-02 Y 100003 Johnson Charles 1995-01-12 Y 100004 Pearson Jeffery 1996-02-06 Y 100005 Sears Miguel 1998-10-31 Y 100006 Kyle Leah 2000-05-29 Y 100007 Myers Lynda 1980-08-24 Yarrow_forwardUse MySQL to list the employee’s first and last name and the department name he/she belongs to.arrow_forward
- How many explicit phrases for the number are there?arrow_forwardSQL Find the guide last name and guide first name of all guides who can lead a paddling triparrow_forwardTable below shows the number of students enrolled in public university for the study field of Science, Mathematics & Computing by programme level and year. Programme Level Year Number of Students Diploma 2019 17373 Bachelor 2019 51640 Master 2019 6918 Doctorate 2019 6292 Diploma 2018 15987 Bachelor 2018 51128 Master 2018 7200 Doctorate 2018 6331 Diploma 2017 15236 Bachelor 2017 49970 Master 2017 6985 Doctorate 2017 648 i) Based on the above table, using the number of students as the key value, draw a Binary Search Tree to store the data.arrow_forward
- A Guide to SQLComputer ScienceISBN:9781111527273Author:Philip J. PrattPublisher:Course Technology PtrNp Ms Office 365/Excel 2016 I NtermedComputer ScienceISBN:9781337508841Author:CareyPublisher:Cengage