INTERVAL of time

From SQLZOO
Revision as of 14:58, 17 July 2012 by Marek (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Intervals of time.

schema:gisq

We can add (or subtract) a number of days (or years, months, hours, minutes or seconds) from date.

In this example we want to find the totp events that went out in the week of my 14th birthday.

 
 
SELECT * FROM totp
WHERE '1976-05-20'
 BETWEEN wk - 7 DAY
     AND wk
SELECT * FROM totp
WHERE #1976-05-20#
 BETWEEN wk - 7 
     AND wk
SELECT * FROM totp
WHERE '1976-05-20'
 BETWEEN DATEADD(DAY,-7,wk)
     AND wk
SELECT * FROM totp
WHERE '1976-05-20'
 BETWEEN wk - 7
     AND wk
SELECT * FROM totp
WHERE '1976-05-20'
 BETWEEN DATE(wk, '-7 days')
     AND wk
SELECT * FROM totp
WHERE DATE '1976-05-20'
 BETWEEN wk - INTERVAL '7' DAY
     AND wk
Personal tools
Namespaces

Variants
Actions
Reference
Toolbox
Google AdSense