Concept explainers
SELECT statement:
It is used to retrieve information from the table or
SELECT * FROM table_Name;
WHERE clause:
“WHERE” statement is used limit the number of rows. For example: Consider a table “FTable” that has two columns named “FruitName” and “Color”. “WHERE” clause is used when there is a need to display the entire FruitName whose color is Red.
SELECT * FROM FTable WHERE color = 'red';
When the above statement is executed, red colored fruits get displayed.
Aggregate Functions:
SQL has some built-in functions and they are called as aggregate functions. SQL contains five built-in functions. They are:
- SUM – This function is used to add values from the particular column.
- Syntax: SELECT SUM(column_Name) FROM table_Name;
- COUNT – This is used to count the number of rows for the particular column.
- Syntax: SELECT COUNT(column_Name) FROM table_Name;
- MAX – This function is used to get the maximum value from the column.
- Syntax: SELECT MAX(column_Name) FROM table_Name;
- MIN – This function is used to get the minimum value from the column.
- Syntax: SELECT MIN(column_Name) FROM table_Name;
- AVG – This function is used to get the average of all the values from the column.
- Syntax: SELECT AVG(column_Name) FROM table_Name;
“ORDER BY” Clause:
SQL contains “ORDER BY” clause in order to sort rows. The values get sorted in ascending and descending order. The keyword used to sort values in ascending order is “ASC” and for descending order is “DESC”. By default, it sorts values by ascending order.
Syntax:
SELECT column_Name1, column_Name2 FROM table_Name ORDER BY column_Name2;
Join:
Join is a relational operation, which combines the data from two or more tables into single table or view, then that is called as Join.
Inner join:
The “inner join” keyword is to select the matching records from two tables. The syntax of “inner join” is as follows:
Syntax:
SELECT column_name FROM table1 INNER JOIN table2 ON table1.column_name=table2.column_name;
“GROUP BY” Clause:
The GROUP BY clause is used to group the result of a SELECT statement done on a table where the tuple values are similar for more than one column.
Syntax:
SELECT expression1, expression2, expression_n, aggregate_function (expression) FROM table_name WHERE conditions GROUP BY expression1, expression2, expression_n;
“AND” operator:
The operator used to check two or more conditions using single query. The “AND” operator returns “true” when two conditions are satisfied in the query.
“BETWEEN” operator:
The “BETWEEN” operator is to selects the in between values within the range given by user.
Syntax:
SELECT column_name1, column_name2, column_namen FROM table_name WHERE column_name BETWEEN range1 AND range2;
Trending nowThis is a popular solution!
Chapter 8 Solutions
Database Systems: Design, Implementation, & Management
- Write a query to display the movie number, movie genre, average cost of movies in that genre, cost of the individual movie, and the percentage difference between the average movie cost and the individual movie cost. The results are shown in Figure P7.98. The percentage difference is the cost of the individual movie minus the average cost of movies in that genre, divided by the average cost of movies in that genre multiplied by 100. For example, if the average cost of movies in the family genre is 25 and a given family movie costs 26, then the calculation would be ((26 25) / 25 100), or 4.00 percent. In this case, the individual movie costs 4 percent more than the average family movie.arrow_forwardRepeat Exercise 6, but this time use the EXISTS operator in your query.arrow_forwardsql queryarrow_forward
- 4. How many customers do we have with a last name starting with a 'Q' living in each city? Your query should display two columns, one named cust_num and one named city. Sort the results alphabeticaly by city. 5. Show the product name, list price, customer state (call it 'CustState'), and manufacturer state (call it 'ManState') for all products made by manufacturers in Connecticut (CT) and purchased by customers in New York (NY). 6. For green sandals, how does the current list price compare to the price at which products have sold? Show the product name, the 7. What is the total number of products sold by each manufacturer? Your query should display two columns, one named productnum and one named manufacturername. Sort the results alphabetically by manufacturername.arrow_forward4. How many customers do we have with a last name starting with a 'Q' living in each city? Your query should display two columns, one named cust_num and one named city. Sort the results alphabeticaly by city. 5. Show the product name, list price, customer state (call it 'CustState'), and manufacturer state (call it 'ManState') for all products made by manufacturers in Connecticut (CT) and purchased by customers in New York (NY). 6. For green sandals, how does the current list price compare to the price at which products have sold? Show the product name, the 7. What is the total number of products sold by each manufacturer? Your query should display two columns, one named productnum and one named manufacturername. Sort the results alphabetically by manufacturername.arrow_forwardWrite a query that returns the Name of ALL Customers (based on CUS_FNAME and CUS_LNAME in CUSTOMER table, call this CUSTOMER_NAME), Phone number of ALL Customers (based on CUS_AREACODE and CUS_PHONE in CUSTOMER table, call this CUSTOMER_PHONE), for those haven’t flied before (based on the record in CHARTER table).arrow_forward
- Database Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781305627482Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781285196145Author:Steven, Steven Morris, Carlos Coronel, Carlos, Coronel, Carlos; Morris, Carlos Coronel and Steven Morris, Carlos Coronel; Steven Morris, Steven Morris; Carlos CoronelPublisher:Cengage LearningA Guide to SQLComputer ScienceISBN:9781111527273Author:Philip J. PrattPublisher:Course Technology Ptr
- Programming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage LearningNp Ms Office 365/Excel 2016 I NtermedComputer ScienceISBN:9781337508841Author:CareyPublisher:Cengage