Skip to content
Advertisement

Calculate total units sold and total sales value

Can you help me check my answers whether is this the right way? Im really new to database

This is the question enter image description here

This is my answer

The reason i use with read only constraint was to enhance the security!

Advertisement

Answer

The way I see it, query would look like this:

If compared to yours:

  • don’t select columns you don’t need (invoicedate) as it affects the final result because you then have to include it into the group by clause so you’d get values “split” per each invoice date as well (and that’s not what you want)

  • properly JOIN tables (i.e. don’t include them in the FROM clause separated by a comma, and then don’t join them in the WHERE clause – put conditions in there

  • condition is related to invoice dates; your code is missing the TO_DATE function, e.g. between to_date('01-01-2021','dd-mm-yyyy'). In this case, I’d suggest you to use date literal which is always in format date 'yyyy-mm-dd'

  • with read only only; nothing else

  • sorting within a view? That doesn’t make much sense (in my opinion). Just create it, and then sort values when you select from the view, e.g.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement