between

mysql between operator with dates

烂漫一生 提交于 2019-12-30 11:20:10
问题 select '2011-02-29' BETWEEN '2011-02-01' AND '2011-03-03'‎ this is returning 1. I think between doesn't consider leap year. I want your view on this? [EDIT] SELECT DATE( '2010-04-31' ) is returning NULL; But select str_to_date('2010-04-31', '%Y-%m-%d') is retuning date. Why? Thanks Venu 回答1: you need to cast it to date like: SELECT DATE('2011-02-29') BETWEEN DATE('2011-02-01') AND DATE('2011-03-03') from the site : For best results when using BETWEEN with date or time values, use CAST() to

Indexing SQL for Between query with only one match?

拥有回忆 提交于 2019-12-30 06:00:56
问题 We have a table with more than two million rows where all queries against it will be a Between lookup using Column1 and Column2 . Also, there will only be one possible result. For example... Col1 Col2 1 5 6 10 11 15 select * from table1 where 8 between Col1 and Col2 I currently have an unique clustered index on Col1 and Col2 . So far I have been unable to figure out how to further tune the query and the indexes to minimize the rows handled. The execution plan currently reports cost of almost

Postgresql query between date ranges

血红的双手。 提交于 2019-12-28 07:58:28
问题 I am trying to query my postgresql db to return results where a date is in certain month and year. In other words I would like all the values for a month-year. The only way i've been able to do it so far is like this: SELECT user_id FROM user_logs WHERE login_date BETWEEN '2014-02-01' AND '2014-02-28' Problem with this is that I have to calculate the first date and last date before querying the table. Is there a simpler way to do this? Thanks 回答1: With dates (and times) many things become

Case in select after sum?

有些话、适合烂在心里 提交于 2019-12-25 06:35:17
问题 I'm trying to assign a different column to a sum depending on the dates. Here's what I have: SELECT SUM(amount) CASE WHEN date BETWEEN '1/1/13' AND '1/1/14' THEN Last_yr_tot WHEN date BETWEEN '1/1/14' AND 'now' THEN YTD My entire query. select fd.location_cd ,round(sum(case when fd.fs_dt between '1/1/13' and '12/31/13' then amount else 0 end)::numeric, 0) as Last_yr ,round(sum(case when fd.fs_dt between '1/1/14' and current_date then amount else 0 end)::numeric, 0) as YTD ,round(sum(case when

Regex that wil match after keyword and before question mark

拥有回忆 提交于 2019-12-25 04:21:23
问题 I'm getting stuck on regex101 with the following test string: https://localhost:8443/site/recipes/recepten-zoeken/menugang:hoofdgerecht/soort:italiaans/seizoen:winter?Nrpp=24 I'm trying to match everything in between: recepten-zoeken/ and ? My current tries lead me nowhere as i'm very novice writing regexes. Anyone wanting to chip in? This is what I currently have: .(?=([^/recepten-zoeken/]?)*$) 回答1: Use capturing group.( () brackets indicates capturing group) Capture upto last question mark

PostgreSQL group by season (northern and southern hemisphere)

北慕城南 提交于 2019-12-24 03:48:10
问题 I have data points distributed over the whole globe. Every data point has a timestamp. I want to group the data by the seasons, as shown in this picture (source: https://en.wikipedia.org/wiki/Season#/media/File:Seasons1.svg). This is what I tried so far (winter 2011/2012 in the northern hemisphere): SELECT * FROM my_table WHERE my_date BETWEEN '2011-12-21' AND '2012-03-21' AND ST_Y(ST_Centroid(geom)) > 0; How can I do this for all possible years? I tried ...OR date BETWEEN... but this is very

Excel - SUMIF INDEX and MATCH

若如初见. 提交于 2019-12-24 01:29:15
问题 I'm stuck with a sumif formula. I think if I used some mix of index and match I could get it to work but I've been unable to do so for the past hour! I need to sum from a table of numbers depending on the house number and 2 dates. For example, I need to sum the numbers for house 1 between dates 08-05-17 and 13-05-17. My previous experience with index and match is that I've only every used it to get a single specific digit. 回答1: OFFSET and INDIRECT are volatile, this is possible with INDEX

Date between dates, ignore year

橙三吉。 提交于 2019-12-23 07:28:36
问题 What's the best (fastest) approach to compare if date is in range of dates independently from year? table "dates": some_column| since | upto | -----------|--------------|-------------| 'foo' | '2011-05-01' | '2013-06-01'| Now I want this query to return 'foo' SELECT foo FROM dates WHERE '2014-05-05' BETWEEN `since` AND `upto` If needed, I can change type/format of stored dates in "dates" table, but I cannot change format of date which I put into query as that value is typically from another

Count number of specific elements in between other elements in list

孤人 提交于 2019-12-22 09:59:42
问题 I am reading a data file. Rows start with consecutive numbers (steps), and sometimes in between each row there is a 0. E.g: 1 0 2 0 3 4 5 0 0 0 6 0 How can I create a list that counts the number of 0s in between each step. I want a list like this: finalList = [1,1,0,0,3,1] which represents the number of 0s each step contains, i.e: step 1 has 1 zero, step 2 has 1 zero, step 3 has 0 zeros, step 4 has 0 zeros, step 5 has 3 zeros and step 6 has 1 zero. 回答1: The following code should work if your

Select where number range does not overlap

我与影子孤独终老i 提交于 2019-12-22 08:19:08
问题 I have two tables that contain records about road construction activites: table_a is the master list. table_b is a legacy list. For each road, in each year, I want to select the records from table_b that do not already exist in table_a . Also, the records should not overlap spatially along the road. More specifically, the from_m and to_m of the records in table_b should not overlap the from_m and to_m in table_a . How can I do this? I do not have Oracle Spatial. The data in Excel (for easy