Informatics Practices
Harjat has created the table EMP in his database.
Table : EMP
| E_ID | Name | Dept | Comm |
|---|---|---|---|
| E001 | Ditya | Admin | 35000 |
| E002 | Uzair | Production | 42500 |
| E003 | Rajnikant | Admin | 21000 |
| E004 | Moushami | Sales | 23575 |
| E005 | Samantha | Sales | 37000 |
| E006 | Sunder | Admin | 43000 |
Now he wants to find the sum of commission earned by each department. He has executed the following query :
SELECT dept, sum(comm)
GROUP BY dept
FROM EMP;
But, he got an error. Rewrite the correct query after identifying the error(s).
SQL Queries
2 Likes
Answer
The error in Harjat's query is the order of the clauses. The GROUP BY clause should come after the FROM clause. The corrected query is as follows :
SELECT dept, sum(comm)
FROM EMP
GROUP BY dept;
Answered By
1 Like
Related Questions
What are aggregate functions? What is their use? Give some examples.
What type of functions can you use with GROUP BY and HAVING clauses ?
Table BOOK_INFORMATION
Column Name BOOK_ID BOOK_TITLE PRICE Which SQL statement allows you to find the highest price from the table BOOK_INFORMATION?
- SELECT BOOK_ID, BOOK_TITLE, MAX(PRICE) FROM BOOK_INFORMATION;
- SELECT MAX(PRICE) FROM BOOK_INFORMATION;
- SELECT MAXIMUM(PRICE) FROM BOOK_INFORMATION;
- SELECT PRICE FROM BOOK_INFORMATION ORDER BY PRICE DESC;
Table SALES
Column Name STORE_ID SALES_DATE SALES_AMOUNT Which SQL statement lets you find the sales amount for each store?
- SELECT STORE_ID, SUM(SALES_AMOUNT) FROM SALES;
- SELECT STORE_ID, SUM(SALES_AMOUNT) FROM SALES ORDER BY STORE_ID;
- SELECT STORE_ID, SUM(SALES_AMOUNT) FROM SALES GROUP BY STORE_ID;
- SELECT STORE_ID, SUM(SALES_AMOUNT) FROM SALES HAVING UNIQUE STORE_ID;