Skip to content
Advertisement

Execute the outer query for each date obtained from inner query

I have the following table BOOKSALES. Some Background about the attributes –

  1. BookID – The unique ID of the book
  2. SaleDate – Date on which the book was sold
  3. RegisterDate – Date on which sale was registered in accounts books

The table looks like this –

Now I want to execute the query that gives me the count of book ids for each sale date, but the register date is less than the sale date. For example- If I want to execute the query for 2nd March, the query will look like-

I want to execute the above query for each date in March . So I tried to rephrase the query as follows

But the above query doesn’t seem to work. Can somebody suggest how to write the above query correctly?

The eventual output should look like –

Advertisement

Answer

The goal of the task is a bit unclear, can’t see what are you trying to achieve. Anyways, your desired output can be returned with this query:

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