Knowee
Questions
Features
Study Tools

Consider the table account given below :Requirement:Jack and John are given the requirement to retrieve the account details and sort details according to location (alphabetically) and in decreasing order of the amount in each of that locations.Jack :SELECT custno, accountno, ifsccode, location, amount, accounttype FROM account ORDER BY location ASC, amount DESC;John :SELECT custno, accountno, ifsccode, location, amount, accounttype FROM account ORDER BY 5 DESC, 4 ASC;Whose query will be correct to satisfy the above requirements?

Question

Consider the table account given below :Requirement:Jack and John are given the requirement to retrieve the account details and sort details according to location (alphabetically) and in decreasing order of the amount in each of that locations.Jack :SELECT custno, accountno, ifsccode, location, amount, accounttype FROM account ORDER BY location ASC, amount DESC;John :SELECT custno, accountno, ifsccode, location, amount, accounttype FROM account ORDER BY 5 DESC, 4 ASC;Whose query will be correct to satisfy the above requirements?

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution 1

The correct query to satisfy the requirements would be Jack's query.

Here's why:

Both Jack and John are trying to retrieve the same columns from the 'account' table. The difference lies in the ORDER BY clause.

Jack's query is ordering the results first by 'location' in ascending order (alphabetically), and then by 'amount' in descending order. This matches the requirement.

John's query, on the other hand, is ordering by the 5th column (which is 'amount') in descending order and then the 4th column (which is 'location') in ascending order. This does not match the requirement because it prioritizes 'amount' over 'location', whereas the requirement is to prioritize 'location' over 'amount'.

So, Jack's query is the correct one.

This problem has been solved

Solution 2

The correct query to satisfy the requirements would be Jack's query.

Here's why:

Both Jack and John are trying to retrieve the same data from the 'account' table. They want to sort the data first by 'location' in ascending order (alphabetically) and then by 'amount' in descending order.

Jack's query does exactly this. He explicitly states to ORDER BY 'location' ASC (ascending), and then 'amount' DESC (descending).

John's query, on the other hand, uses column numbers instead of column names in the ORDER BY clause. He states to ORDER BY 5 DESC, 4 ASC. In SQL, the column numbers start from 1. So, 5 refers to 'amount' and 4 refers to 'location'. However, he is ordering by 'amount' in descending order first and then 'location' in ascending order. This does not meet the requirement.

Therefore, Jack's query is the correct one.

This problem has been solved

Similar Questions

Which SQL clause is used to sort the result set in descending order based on one or more columns?

How would you sort the results by "amount" in descending order?SELECT * FROM expenses ORDER BY amount ASC; SELECT * FROM expenses ORDER BY amount DESC;SELECT * FROM expenses SORT BY amount DESC;SELECT * FROM expenses ORDER BY amount;

What is the purpose of the ORDER BY clause in an SQL statement?To filter records based on specified conditions To sort the retrieved dataTo group recordsTo limit the number of records retrieved

ORDER BY and GROUP BY clauses can be used to sort the results in a specific order.

Write a query to display the meter_number,owner_name and address of the owner who paid second least  fine total amount. If there are multiple records display in ascending order based on owner name.Note:1. Display only the below 3 columns,     i. meter number     ii. owner name     iii. address  with the condition who paid seocnd least fine total amount.2. Use Joins3. Tables involved are building, meter and bill4. Order by is mandatory.5. Compare your executed result with the sample output given below.Sample output:

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.