SQL selects a maximum of two time periods

I have a query, I'm trying to select the maximum value from the summer period (November-April here), but it gives me only the values ​​from nov-dec with this query. Any ideas why?

SELECT TOP 10 Value, DateTime 
  FROM history
 WHERE Tagname = @Tag
   AND 
       ((DateTime >= @StartYear AND DateTime < @StartWinter)
    OR 
       (DateTime >= @FinishWinter AND DateTime < @FinishYear))
ORDER BY Value DESC
+3
source share
3 answers

Hi, thanks for helping everyone, it seems to be a problem with our historian (related db to sql server), so I take care of this problem. I tried the mssql db request on a regular basis and it looks great ...

0
source

(DateTime> = startYear AND datetime <startwinter) gives you all the results between jan and april 2009. (Datetime> finishwinter and datetime <finishyear) gives all the results in November dec 09.

, 2009 . , , 2009 , , ?

@startwinter , jan-apr 2010.

0

"ORDER BY" "TOP 10"?

, , : (@StartYear, @StartWinter, @FinishWinter, @FinishYear)

:

  • StartYear = 2010-01-01
  • FinishYear = 2010-12-31
  • StartWinter = 2010-12-20 ()
  • FinishWinter = 2010-03-20 ()

, 2010-01-01 2010-12-20 (), - 2010 .

, , , 03.20 12.20 double.

0

Source: https://habr.com/ru/post/1742741/


All Articles