skip to Main Content

enter image description here

I want to get the count of ‘unitsold’ for each Name from 3/1/2022 and 4/1/2022. For example Name ‘a’ required to count its units sold from 3rd to 8th day.

SQL query:

select Name, sum(unitsold) over (partion by Name order by Asc) from table1

The above query will provide units sold for the entire date range. But how to get sum of units sold from 3rd day to 8th day of each name?

2

Answers


  1. Chosen as BEST ANSWER

    enter image description here

    This is the query which gives the out put.


  2. Select name, sum (CASE when date >= '22/03/03' AND date <='22/03/08' then unitsold else 0 end) as totalUnitsSold
    From table1 where 
    Date >='22/03/01' and Date <='22/03/01'
    Group by Name;
    

    The case handles day logic and where clause handles the date range of 1 month.

    Hope this helps, Thanks.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search