N
N
Nikita_Migushev2021-05-26 08:19:52
SQL
Nikita_Migushev, 2021-05-26 08:19:52

How to get the status for a date using SQL?

Good afternoon!

There is a table with articles, statuses and status validity dates.

It is necessary to write a request that will issue a list of articles and their current statuses for a certain date.

For example, on the date 02/18/2021

Please tell me how to do it.

Item	Status	DateFrom	DateTo
1	Status1	01.01.2021	10.01.2021
1	Status2	11.01.2021	15.02.2021
1	Status3	16.02.2021	15.03.2021
2	Status1	01.01.2021	10.01.2021
2	Status2	11.01.2021	15.02.2021
2	Status3	16.02.2021	15.03.2021
3	Status1	01.01.2021	10.01.2021
3	Status2	11.01.2021	15.02.2021
3	Status3	16.02.2021	15.03.2021

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
idShura, 2021-05-26
@Nikita_Migushev

select * from mytable where нужная_дата between DateFrom and DateTo

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question