gaps-and-islands

Student absent for 5 consecutive days excluding Holidays

微笑、不失礼 提交于 2020-01-30 04:04:57
问题 I am using code igniter and attendance table as below: attendance ID timestamp student_id status 1 01-01-20 1 P 2 01-01-20 2 P 3 02-01-20 1 P 4 02-01-20 2 A 5 03-01-20 1 P 6 03-01-20 2 A 7 04-01-20 1 H 8 04-01-20 2 H 9 05-01-20 1 P 10 05-01-20 2 A My target is to get the student id who is absent for 3 consecutive days for the period of the last 1 month from today excluding the holidays in the middle like in the above table the student id 2 should be the one with 3 consecutive absence

Student absent for 5 consecutive days excluding Holidays

给你一囗甜甜゛ 提交于 2020-01-30 04:04:16
问题 I am using code igniter and attendance table as below: attendance ID timestamp student_id status 1 01-01-20 1 P 2 01-01-20 2 P 3 02-01-20 1 P 4 02-01-20 2 A 5 03-01-20 1 P 6 03-01-20 2 A 7 04-01-20 1 H 8 04-01-20 2 H 9 05-01-20 1 P 10 05-01-20 2 A My target is to get the student id who is absent for 3 consecutive days for the period of the last 1 month from today excluding the holidays in the middle like in the above table the student id 2 should be the one with 3 consecutive absence

Count Consecutive Numeric values in SQL

末鹿安然 提交于 2020-01-26 03:55:48
问题 There are already many existing questions about this scenario, however I am unable to replicate the answers in my scenario. I have a following sample Data Set: ID Number | Values 754321 0 754321 0 754321 0 754321 0 754321 1 754321 0 754321 1 754321 0 754321 2 754321 0 754329 3 754329 4 754329 5 754329 6 754329 7 754329 8 754329 9 I want the SQL query that outputs the ID Number with the number of times the value of "0" appears consecutively. So, for the above table I would like to get the

Count Consecutive Numeric values in SQL

允我心安 提交于 2020-01-26 03:55:09
问题 There are already many existing questions about this scenario, however I am unable to replicate the answers in my scenario. I have a following sample Data Set: ID Number | Values 754321 0 754321 0 754321 0 754321 0 754321 1 754321 0 754321 1 754321 0 754321 2 754321 0 754329 3 754329 4 754329 5 754329 6 754329 7 754329 8 754329 9 I want the SQL query that outputs the ID Number with the number of times the value of "0" appears consecutively. So, for the above table I would like to get the

group consecutive time intervals in sql

六月ゝ 毕业季﹏ 提交于 2020-01-24 20:08:25
问题 Assuming a data structure of the type stock_name, action, start_date, end_date google, growing, 1, 2 google, growing, 2, 3 google, falling, 3, 4 google, growing, 4, 5 yahoo, growing, 1, 2 How can I aggregate it to merge consecutive time intervals? The output would look like: stock_name, action, start_date, end_date google, growing, 1, 3 google, falling, 3, 4 google, growing, 4, 5 yahoo, growing, 1, 2 I thought of using rank window function to number the consecutive with a constant and then

group consecutive time intervals in sql

前提是你 提交于 2020-01-24 20:07:58
问题 Assuming a data structure of the type stock_name, action, start_date, end_date google, growing, 1, 2 google, growing, 2, 3 google, falling, 3, 4 google, growing, 4, 5 yahoo, growing, 1, 2 How can I aggregate it to merge consecutive time intervals? The output would look like: stock_name, action, start_date, end_date google, growing, 1, 3 google, falling, 3, 4 google, growing, 4, 5 yahoo, growing, 1, 2 I thought of using rank window function to number the consecutive with a constant and then

group consecutive time intervals in sql

末鹿安然 提交于 2020-01-24 20:07:16
问题 Assuming a data structure of the type stock_name, action, start_date, end_date google, growing, 1, 2 google, growing, 2, 3 google, falling, 3, 4 google, growing, 4, 5 yahoo, growing, 1, 2 How can I aggregate it to merge consecutive time intervals? The output would look like: stock_name, action, start_date, end_date google, growing, 1, 3 google, falling, 3, 4 google, growing, 4, 5 yahoo, growing, 1, 2 I thought of using rank window function to number the consecutive with a constant and then

Postgresql Table Same Data last adjacent occurance and first In One row

谁说我不能喝 提交于 2020-01-24 00:23:16
问题 I have a program that checks status of Computers in a network by PING each minutes. Each time it will insert a new row to DB as follows (I'm using postgresql) id_status status checking_time(timestamp) id_device(int) 1 OK '2017-01-01 00:00:00' 1 2 OK '2017-01-01 00:00:00' 2 3 OK '2017-01-01 00:00:00' 3 4 Failed '2017-01-01 00:01:00' 1 5 OK '2017-01-01 00:01:00' 2 6 OK '2017-01-01 00:01:00' 3 7 Failed '2017-01-01 00:02:00' 1 8 OK '2017-01-01 00:02:00' 2 9 OK '2017-01-01 00:02:00' 3 10 Failed

Mark non-contiguous date ranges

女生的网名这么多〃 提交于 2020-01-14 07:37:50
问题 Background (Input) The Global Historical Climatology Network has flagged invalid or erroneous data in its collection of weather measurements. After removing these elements, there are swaths of data that no longer have contiguously dated sections. The data resembles: "2007-12-01";14 -- Start of December "2007-12-29";8 "2007-12-30";11 "2007-12-31";7 "2008-01-01";8 -- Start of January "2008-01-02";12 "2008-01-29";0 "2008-01-31";7 "2008-02-01";4 -- Start of February ... entire month is complete .

Make Postgres choose the next minimal available id

这一生的挚爱 提交于 2020-01-13 10:25:31
问题 I would like to make Postgres choose the first next available id so that no error occurs in the following case: CREATE TABLE test( id serial PRIMARY KEY, name varchar ); Then: INSERT INTO test VALUES (2,'dd'); INSERT INTO test (name) VALUES ('aa'); INSERT INTO test (name) VALUES ('bb'); This will give a constraint error since id is primary. How can I tell Postgres to insert the record with the next free id? 回答1: Generally it's best to never overrule the default in a serial column. If you