date-range

SQL Date Range Split

廉价感情. 提交于 2019-12-03 10:48:19
问题 Can you please let me know the SQL to split date ranges when they overlap? Data (sample data with a date range and possibly other columns): Col1 FromDate ToDate 1. 1 1/1/2008 31/12/2010 2. 1 1/1/2009 31/12/2012 3. 1 1/1/2009 31/12/2014 Output: Col1 From Date ToDate 1. 1 1/1/2008 31/12/2008 (from row 1 above) 2. 1 1/1/2009 31/12/2010 (from rows 1,2 and 3 above) 3. 1 1/1/2011 31/12/2012 (from rows 2 and 3 above) 4. 1 1/1/2013 31/12/2014 (from row 3 above) 回答1: This should do the trick (MySQL

Pandas date_range to generate monthly data at beginning of the month

泄露秘密 提交于 2019-12-03 08:06:08
问题 I'm trying to generate a date range of monthly data where the day is always at the beginning of the month: pd.date_range(start='1/1/1980', end='11/1/1991', freq='M') This generates 1/31/1980 , 2/29/1980 , and so on. Instead, I just want 1/1/1980 , 2/1/1980 ,... I've seen other question ask about generating data that is always on a specific day of the month, with answers saying it wasn't possible, but beginning of month surely must be possible! 回答1: You can do this by changing the freq

ORACLE SQL Date range intersections

浪子不回头ぞ 提交于 2019-12-03 07:26:21
问题 I have a table T1, it contains a NAME value (not unique), and a date range (D1 and D2 which are dates) When NAME are the same, we make a union of the date ranges (e.g. B). But as a result (X), we need to make intersection of all the date ranges Edit: Table T1 NAME | D1 | D2 A | 20100101 | 20101211 B | 20100120 | 20100415 B | 20100510 | 20101230 C | 20100313 | 20100610 Result : X | 20100313 | 20100415 X | 20100510 | 20100610 Visually, this will give the following : NAME : date range A : [-----

Pandas date_range to generate monthly data at beginning of the month

风流意气都作罢 提交于 2019-12-02 21:38:22
I'm trying to generate a date range of monthly data where the day is always at the beginning of the month: pd.date_range(start='1/1/1980', end='11/1/1991', freq='M') This generates 1/31/1980 , 2/29/1980 , and so on. Instead, I just want 1/1/1980 , 2/1/1980 ,... I've seen other question ask about generating data that is always on a specific day of the month, with answers saying it wasn't possible, but beginning of month surely must be possible! You can do this by changing the freq argument from 'M' to 'MS' : d = pandas.date_range(start='1/1/1980', end='11/1/1990', freq='MS') print(d) This

ORACLE SQL Date range intersections

瘦欲@ 提交于 2019-12-02 20:59:33
I have a table T1, it contains a NAME value (not unique), and a date range (D1 and D2 which are dates) When NAME are the same, we make a union of the date ranges (e.g. B). But as a result (X), we need to make intersection of all the date ranges Edit: Table T1 NAME | D1 | D2 A | 20100101 | 20101211 B | 20100120 | 20100415 B | 20100510 | 20101230 C | 20100313 | 20100610 Result : X | 20100313 | 20100415 X | 20100510 | 20100610 Visually, this will give the following : NAME : date range A : [-----------------------]----- B : --[----]---------------------- B : ----------[---------------]--- C : ----

Using a SQL query, how can I select every date within a range?

懵懂的女人 提交于 2019-12-02 19:53:13
问题 I'm querying a support ticket database, and each ticket has a column for "date opened" and "date closed." Tickets frequently remain open for multiple days, so we need to be able to pull the number of tickets that are OPEN on each day. For example, for 4/8/14, we need to know how many tickets were opened on 4/8, combined with the total number of unclosed tickets that were opened prior to 4/8 but remained still open at 12:00am on 4/8 (may or may not have been closed during or after 4/8). This

PostgreSQL, min, max and count of dates in range

心不动则不痛 提交于 2019-12-02 10:16:13
问题 This question is based of two previous here and here. I am trying very hard to get those two queries: SELECT min(to_date(nullif(mydatetext,''), 'DD.MM.YYYY')) AS dmin, max(to_date(nullif(mydatetxt,''), 'DD.MM.YYYY')) AS dmax FROM mytable and SELECT count(*) FROM mytable WHERE to_date(nullif(mydatetxt,'')) 'ERROR HERE BETWEEN max(to_date(nullif(mydatetxt,''), 'DD.MM.YYYY')) AND min(to_date(nullif(mydatetxt,''), 'DD.MM.YYYY')) in single one so I can read result as minimal date, maximal date,

SQL Date Query include month even if no data

纵饮孤独 提交于 2019-12-02 08:56:27
I have a booking database with various dates for each booking. I want to get a count of all bookings in each month e.g. JAN | 12 FEB | 15 MAR | 53 APR | 25 If I have zero bookings in a month, how can I still get the month listed? e.g.: JAN | 12 FEB | 15 MAR | 53 APR | 0 MAY | 52 Schema: ID | BookingDate | REF I don't have or want to have a months table to join against. Below is my query so far: SELECT TOP 1000 [Id] ,[MemberId] ,[LocationId] ,[Date] ,[BookingStateId] ,[RPEFeeling] ,[RPEPush] ,[Notes] ,[TimeSlotId] ,[MembershipId] ,[TrialSession] ,[CreatedDate] ,[ModifiedDate] ,[CreatedBy] ,

How to create a 'past 3 months' time period in Google Data Studio

独自空忆成欢 提交于 2019-12-02 07:38:43
问题 I'm trying to have my line chart show data for the past 3 months. GDS has a 'last quarter' date range, but this shows me Q1, Q2, Q3, or Q4. What I need is the data for the past 3 full months (not counting the current month). I tried creating a calculated field but the documentation isn't proving very useful for the matter at hand. eg. If the current date is Feb-20, I want to show data from 'Nov 1 - Jan 31'. Also need to compare to same period from last year. Can anyone help? Thanks in advance

PostgreSQL, min, max and count of dates in range

☆樱花仙子☆ 提交于 2019-12-02 07:00:30
This question is based of two previous here and here . I am trying very hard to get those two queries: SELECT min(to_date(nullif(mydatetext,''), 'DD.MM.YYYY')) AS dmin, max(to_date(nullif(mydatetxt,''), 'DD.MM.YYYY')) AS dmax FROM mytable and SELECT count(*) FROM mytable WHERE to_date(nullif(mydatetxt,'')) 'ERROR HERE BETWEEN max(to_date(nullif(mydatetxt,''), 'DD.MM.YYYY')) AND min(to_date(nullif(mydatetxt,''), 'DD.MM.YYYY')) in single one so I can read result as minimal date, maximal date, count of dates between and including min and max dates. But here are few problems. Second query don't