gaps-and-islands

Return duration of an item from its transactions, many to many, SQL

不问归期 提交于 2020-07-04 00:19:01
问题 Hopefully I can get some help on this. Situation There are two incoming stations and one outgoing station. Items are scanned in and out. I need to know how long an item was in the station. Let's consider 'in station' to be the time between it's incoming date scan and it's outgoing date scan. Problem An item can be (accidentally) scanned multiple times into either station (for this I was thinking of identifying if a scan was made the same day (not looking at hours) then return the earliest

Return duration of an item from its transactions, many to many, SQL

|▌冷眼眸甩不掉的悲伤 提交于 2020-07-04 00:18:12
问题 Hopefully I can get some help on this. Situation There are two incoming stations and one outgoing station. Items are scanned in and out. I need to know how long an item was in the station. Let's consider 'in station' to be the time between it's incoming date scan and it's outgoing date scan. Problem An item can be (accidentally) scanned multiple times into either station (for this I was thinking of identifying if a scan was made the same day (not looking at hours) then return the earliest

Select only rows that has a column changed from the rows before it, given an unique ID

ぐ巨炮叔叔 提交于 2020-06-27 16:57:50
问题 I have a postgreSQL database where I want to record how a specific column changes for each id, over time. Table1: personID | status | unixtime | column d | column e | column f 1 2 213214 x y z 1 2 213325 x y z 1 2 213326 x y z 1 2 213327 x y z 1 2 213328 x y z 1 3 214330 x y z 1 3 214331 x y z 1 3 214332 x y z 1 2 324543 x y z I want to track all the of status over time. So based on this I want a new table, table2 with the following data: personID | status | unixtime | column d | column e |

SQL Query to get count of cycles if it matches value of column in consecutive rows

僤鯓⒐⒋嵵緔 提交于 2020-06-09 07:06:08
问题 I have table named vehicledata which consists 3 columns: id , Veh No , and Veh Mode . My data looks like this: id Veh No Veh Mode 1 KA03-003 IDLE 2 KA03-003 IDLE 3 KA03-003 IDLE 4 KA03-003 DRIVE 5 KA03-003 DRIVE 6 KA03-003 DRIVE 7 KA03-003 DRIVE 8 KA03-003 DRIVE 9 KA03-003 IDLE 10 KA03-003 IDLE 11 KA03-003 IDLE 12 KA03-003 DRIVE 13 KA03-003 DRIVE 14 KA03-003 DRIVE 15 KA03-003 DRIVE 16 KA05-005 IDLE 17 KA05-005 IDLE 18 KA05-005 IDLE 19 KA05-005 DRIVE 20 KA05-005 DRIVE 21 KA05-005 DRIVE 22 KA05

C# 'invert' list of DateTime

Deadly 提交于 2020-04-14 03:45:43
问题 I have a list of DateTimes and I need to 'invert' (for lack of a better word) this list. public class Available { public Available(DateTime startDate, DateTime endDate) { if (!startDate.Day.Equals(endDate.Day)) throw new Exception("The start and end days are not equal."); this.StartDate = startDate; this.EndDate = endDate; } public DateTime StartDate { get; set; } public DateTime EndDate { get; set; } } List<Available> availableTimes = new List<Available>() { new Available(new DateTime(2015,

SQL or LINQ: how do I select records where only one paramater changes?

南楼画角 提交于 2020-02-16 12:21:09
问题 Say we have this list: Id IdRef myColumn anotherColumn 448 70 1 228 449 70 1 2s8 451 70 1 228 455 70 2 2a8 456 70 2 s28 457 70 2 28 458 70 3 v 459 70 3 28 460 70 4 22 461 70 3 54 462 70 4 45 463 70 3 s28 I need to select a list with a record everytime "myColumn" changes. So the result would be: Id IdRef myColumn anotherColumn 448 70 1 228 455 70 2 2a8 458 70 3 v 460 70 4 22 461 70 3 54 462 70 4 45 463 70 3 s28 回答1: This is a gaps and islands problem. In SQL, here is one approach to solve it

Mysql sum of records by month for the last 12 months

别等时光非礼了梦想. 提交于 2020-02-02 12:03:23
问题 Hello I'm using this sql query to get the last 12 month records based on month for chart representation: SELECT DATE_FORMAT(drives.timestamp, "%b") AS Month, DATE_FORMAT(drives.timestamp, "%d-%m-%Y %H:%i:%s") AS Exact_date, drives.departure, drives.destination, drives.route, CONCAT(drivers.name, " ", drivers.surname) as driver, drivers.id as driver_id FROM drives, drivers WHERE drives.driver = drivers.id AND drives.timestamp > DATE_SUB(now(), INTERVAL 12 MONTH) ORDER BY drives.timestamp Asc

Mysql sum of records by month for the last 12 months

╄→尐↘猪︶ㄣ 提交于 2020-02-02 12:02:33
问题 Hello I'm using this sql query to get the last 12 month records based on month for chart representation: SELECT DATE_FORMAT(drives.timestamp, "%b") AS Month, DATE_FORMAT(drives.timestamp, "%d-%m-%Y %H:%i:%s") AS Exact_date, drives.departure, drives.destination, drives.route, CONCAT(drivers.name, " ", drivers.surname) as driver, drivers.id as driver_id FROM drives, drivers WHERE drives.driver = drivers.id AND drives.timestamp > DATE_SUB(now(), INTERVAL 12 MONTH) ORDER BY drives.timestamp Asc