-2

I want to find data for the last 20 Tuesday.

        Date                    value
2020-03-03 01:12:15               5
2020-02-25 07:12:15               13
2020-02-24 08:12:15               1
2020-02-23 09:12:15               32
2020-02-22 10:12:15               7
2020-02-21 11:12:15               43
2020-02-20 12:12:15               7
2020-02-19 13:12:15               1
2020-02-18 14:12:15               31
2020-02-17 15:12:15               14

and so one

My desired output is

        Date                    value
2020-03-03 01:12:15               5
2020-02-25 07:12:15               13
2020-02-18 14:12:15               31

and so on

ashishmishra
  • 363
  • 2
  • 14
  • Please see: [Why should I provide an MCRE for what seems to me to be a very simple SQL query?](https://meta.stackoverflow.com/questions/333952/why-should-i-provide-a-minimal-reproducible-example-for-a-very-simple-sql-query) – Strawberry Mar 09 '20 at 11:04
  • Last 20 Tuesdays? With and without values? (I.e. any Tuesday from the last 20 * 7 + 6 dates?) – jarlh Mar 09 '20 at 11:04

3 Answers3

1

Is this what you want?

select t.*
from t
where weekday(date) = 2
order by date desc
limit 3  -- or 20
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
1

You can use below query

select t.*
from t
where weekday(date) = 2
order by date desc
limit 20
Rahul Koshti
  • 186
  • 1
  • 10
0

You could use year and dayofweek

select  * from  myTable  
where year(date) = 2020
and dayofweek(date) = 5
ScaisEdge
  • 131,976
  • 10
  • 91
  • 107