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.
“SUM” function:
- It is the one function of aggregate function.
- The “SUM” function is used to compute the total of the values in a column.
Example:
The example for “SUM” function is given below:
SELECT SUM(MARK_CREDIT) FROM STUDENT;
The above query is used to display the sum of all students mark credit from “STUDENT” table using “SUM” function.
“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.
“HAVING” Clause:
- The “HAVING” clause is used to restrict the groups that are included.
- This restriction does not apply to individual rows but relatively apply to groups.
Example:
The example for “HAVING” clause is given below:
SELECT STUDENT_ID, NAME, AGE, ADDRESS, TOTAL_MARK FROM STUDENTS GROUP BY AGE HAVING COUNT(AGE) >= 10;
- The above query is used to display a record for a similar age count that would be more than or equal to “10”.
Trending nowThis is a popular solution!
Chapter 4 Solutions
A Guide to SQL
- How do you indicate that a column alias should be used?arrow_forward7. Use the UNION operator to generate a result set consisting of three columns from the Products table: Discount status A calculated column that contains a value of DISCOUNTED or FULL PRICE Product_name The product_name column discount_percent The discount_percent column If the product has a discount_percent greater than 0, the Discount_status column should contain a value of DISCOUNTED. Otherwise, it should contain a value of FULL PRICE. Sort the final result set by product_name.arrow_forward9. Find the total amount of tax paid by resident of NJ Hint: The tax cost stored in tax_amount column in the orders table The state name stored in state column in the addresses tablearrow_forward
- You have been told that you need to store the zip code for employees. Add a column to the EMPLOYEE table which will be used to store each employee’s zip code Update two rows in the EMPLOYEE table and assign a zip code (must have a WHERE clause). (you MAY use 1 or 2 statements) Write a query that includes each employee's last name, department name (not ID), and salary for each employee whose salary is less than the average for their departmentarrow_forwardWrite a ASQ statement to return to see all of the first names in the People table. SELECT first name FROM people; WHERE FROM People first name; FROM People SELECT first_name; First name WHERE FROM People;arrow_forwardQ1- List all employees whose job_id is IT_PROG and hired after 01-JAN-95 and earning more than5000.Q2- List all employee except those with employee_id 101, 102, 103, 104 and 105Q3- Display the city attribute from locations table. Show the ones that contain “South” in the city.Sort the list in descending order.Q4- Display the first name, last name, salary, manager id and job id of all employees whose last fourcharacters of job id ends with “LERK”.Q5- Display the first name, last name and salary of all employees. Round the salary to the nearestunit of 1000 (ex. Salary=4500 New Salary=5000). Label the column as "New Salary".arrow_forward
- Can you enter null value in a column where the Unique constraint is assigned to that column True Falsearrow_forwardi want the codes of create table and insert table only pleasearrow_forwardSQL: For every invoice, display the invoice number, invoice date and the total dollar amount for all products purchased in the invoice, ordered by invoice number in descending order and then by invoice date in ascending order. Here you will use an aggregate SUM(x,y) function in your SELECT clause to calculate the total dollar amount (a calculated field – name it TOTAL). Don’t forget to join on the tables as well. [hint: you should have 8 rows of output ordered properly]. My code is as follows: select inv_number, inv_date, sum(line_price) as 'total' from invoice, line where invoice.inv_number = line.inv_number order by inv_number desc, inv_date asc ; I am getting this error: ORA-00923: FROM keyword not found where expected Any recommendations on what I am doing wrong?arrow_forward
- SQL: For every invoice, display the invoice number, invoice date and the total dollar amount for all products purchased in the invoice, ordered by invoice number in descending order and then by invoice date in ascending order. Here you will use an aggregate SUM(x,y) function in your SELECT clause to calculate the total dollar amount (a calculated field – name it TOTAL). Don’t forget to join on the tables as well. [hint: you should have 8 rows of output ordered properly]. select inv_number, inv_date sum(list_price) as 'total' from invoice, line order by desc inv_num, asc inv_date. I am getting the error: ORA-00923: FROM keyword not found where expected Am I formulating the query incorrectly?arrow_forwardDisplay a list of all book titles and the percentage of markup for each book. The percentage of markup should be displayed as a whole number (that is, multiplied by 100) with no decimal position, followed by a percent sign (for example, .2793 = 28%). (The percentage of markup should reflect the difference between the retail and cost amounts as a percent of the cost. (refer to the tables in the JustLee Books database.)arrow_forward7. SELECT name FROM instructor WHERE salary = 90000; This query can be replaced by which of the following ? a) SELECT name FROM instructor WHERE salary BETWEEN 90000 AND 100000; b) SELECT name FROM employee WHERE salary =100000; c) SELECT name FROM employee WHERE salary BETWEEN 90000 AND 100000; d) SELECT name FROM instructor WHERE salary BETWEEN 100000 AND 90000;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
- COMPREHENSIVE MICROSOFT OFFICE 365 EXCEComputer ScienceISBN:9780357392676Author:FREUND, StevenPublisher:CENGAGE LProgramming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage Learning