MySQL SQL SUM() A sql-6-5.sql file has been opened for you. Write each of the fo
ID: 3905171 • Letter: M
Question
MySQL
SQL SUM()
A sql-6-5.sql file has been opened for you.
Write each of the following tasks as a SQL statement in a new line (remember that you can source the file to compare the output reference):
1 - Use the e_store database
2 - Select the total stock of all products in the products table. Alias the column name as total_stock. The resulting table should look like this:
3 - Select the total stars of the product with id = 4. Alias the column name as total_stars. The resulting table should look like this:
Explanation / Answer
1)Syntax: USE DATABASE_NAME;
Ans --> USE e_store;
2)Syntax: SELECT SUM(COLUMN_NAME) AS OUTPUT_COLUMN_NAME FROM TABLE_NAME;
Ans --> SELECT SUM(stock) AS total_stock FROM products;
3)Syntax: SELECT COLUMN_NAME FROM TABLE_NAME WHERE CONDITION;
Ans --> SELECT total_stars FROM products WHERE id=4;
You have not mentioned the table structure so use column names as per your products table.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.