Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7050563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:09:31+00:00 2026-05-28T03:09:31+00:00

Given a table with the following two columns 1) Date, DATE 2) Weather, INTEGER

  • 0

Given a table with the following two columns
1) Date, DATE
2) Weather, INTEGER (0=ClearDay, 1=Rain, 2=Snow)

I’d like a SELECT that returns ALL dates when it rained AND snowed within -+ (N,M) days from the day it rained. I.e., if (-+)N,M=1,2 and it rained today (Wed) I’d want today’s date returned if it snowed on any day from Tue to Fri included, assuming only one weather value per day.

  • Example 1:
  • 1/1/2011, 0
  • 1/1/2011, 0
  • 1/2/2011, 2
  • 1/3/2011, 1
  • 1/4/2011, 1
  • 1/5/2011, 0
  • 1/6/2011, 0

With (-+)N,M=2,1 – return 1/3, 1/4

  • Example 2:
  • 1/1/2011, 0
  • 1/2/2011, 2
  • 1/3/2011, 1
  • 1/4/2011, 1
  • 1/5/2011, 1
  • 1/6/2011, 0
  • 1/7/2011, 2

With (-+)N,M=1,2, return 1/3, 1/5

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T03:09:32+00:00Added an answer on May 28, 2026 at 3:09 am

    This query should do it for you. Replace @N with the number of days before and @M with the number of days after to check. Note that I assume your table’s name is t.

    SELECT DISTINCT rain.date
    FROM t AS rain
    JOIN t AS snow ON snow.date between rain.date - @N AND rain.date + @M 
        AND snow.weather = 2
    WHERE rain.weather = 1
    

    I’m having trouble deciding what the correct way is to compare the dates in sqlite. I’ve tried looking it up but I’m getting conflicting advice. This sqlite doc page made it sound like julianday was the best way to compare just the DAY part of a DATE. If the above query doesn’t work for you, try this version instead which uses julianday to get just the DAY component of the date.

    SELECT DISTINCT rain.date
    FROM t AS rain
    JOIN t AS snow ON julianday(snow.date) between julianday(rain.date) - @N AND julianday(rain.date) + @M 
        AND snow.weather = 2
    WHERE rain.weather = 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Problem Given the following two tables, I'd like to select all Ids for Posts
The following two queries each give the same result: SELECT column FROM table GROUP
I have a MySQL table with the following columns: id(int), date (timestamp), starttime(varchar), endtime(varchar),
I have a SQL table with two columns Date and User and contains the
Given a table (daily_sales) with say 100k rows of the following data/columns: id rep
Given the following table in SQL Server 2005: ID Col1 Col2 Col3 -- ----
I have a necessity to sort a given HTML table of the following structure,
This came up when answering another user's question (TheSoftwareJedi)... Given the following table: ROW_PRIORITY
Given an Oracle table created using the following: CREATE TABLE Log(WhenAdded TIMESTAMP(6) WITH TIME
Given a table (id, col1, col2), does it make sense to create the following

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.