w3resource

AdventureWorks Database: Expression used in group by

SQL Query - AdventureWorks: Exercise-10 with Solution

10. From the following table write a query in SQL to find the total quentity for a group of locationid multiplied by 10.

Sample table: production.productinventory


Click to view Full table

Sample Solution:

SELECT SUM(quantity) AS total_quantity
FROM production.productinventory
GROUP BY (locationid*10);

Sample Output:

total_quantity|
--------------+
           186|
         20295|
           110|
         83173|
         17319|
          5549|
         72899|
           958|
         13584|
           332|
         95477|
          5165|
         20419|
           508|

SQL AdventureWorks Editor:

Practice Online


Contribute your code and comments through Disqus.

Previous: Find total quantity of each product in specific shelves.
Next: Persons whose last name begins with 'L'.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Share this Tutorial / Exercise on : Facebook and Twitter

SQL: Tips of the Day

T-SQL Cast versus Convert?

CONVERT is SQL Server specific, CAST is ANSI.

CONVERT is more flexible in that you can format dates etc. Other than that, they are pretty much the same. If you don't care about the extended features, use CAST.

Ref : https://bit.ly/3VKT5M8