condition is: Today value is more than yesterday and yesterday more than the day before if this happened show else not show select * from mytable where all records 2018-01-03 2018-01-02 2018-01-01 | > | > | value value value in last 3 day and Every day more than the day before (Today is more than yesterday and yesterday more than the day before if this happened show else not show) +-----------------------------------+ name date value ----------------------------- apple 2018-01-03 1000 lg 2018-01-03 2000 sony 2018-01-03 2000 bmw 2018-01-03 3000 apple 2018-01-02 2000 lg 2018-01-02 1000 sony 2018-01-02 2500 bmw 2018-01-02 2000 apple 2018-01-01 500 lg 2018-01-01 500 sony 2018-01-01 3000 bmw 2018-01-01 1000 +-----------------------------------+ I need the following result: +-----------------------------------+ name date value ----------------------------- lg 2018-01-03 2000 bmw 2018-01-03 3000 lg 2018-01-02 1000 bmw 2018-01-02 2000 lg 2018-01-01 500 bmw 2018-01-01 1000 +-----------------------------------+ Thanks all
答案 0 :(得分:0)
SELECT * FROM mytable where
(date BETWEEN '2018-01-01' AND '2018-01-03')
AND
(name = 'lg' AND name = 'bmw')
答案 1 :(得分:0)
select name
,date
,value
from
(select t1.name as name
,t1.date as date
,t1. value as value
,t2.value as date_minus_1_value
,t3.value as date_minus_2_value
from mytable t1
inner join mytable t2
on t1.name = t2.name and t1.date = date_add(t2.date,interval -1 day)
inner join mytable t3
on t1.name = t3.name and t1.date = date_add(t3.date,interval -2 day)
)
where (value > date_minus_1_value and date_minus_1_value >
date_minus_2_value)
答案 2 :(得分:0)
SELECT * FROM Mytable WHERE mytable.date> DATEADD(dd,-3,GETDATE())