Sorry for the noob SQL question. I have a table in SQL with a DateTime column. I need to run a script daily to show any lines from 8am yesterday until 8am today. So for example, today I would run: I also know that I could run this, but this will only give me the previous day through the current
Tag: datetime
Making cumulative sum with ids and dates in MySQL
Imagine I have this: id transactiondate transactiontag clientid transactionvalue 1 2020-12-28 pizza 0 29.99 2 2020-12-29 payment 0 -39.99 3 2020-12-28 cheese 0 -109.99 4 2020-12-28 cheese 0 -109.99 5 2020-12-28 pizza 1 -19.99 6 2020-12-28 cheese 1 -18.99 7 2020-12-28 salary 1 58.99 8 2020-12-29 salary 1 38.99 So I have all the Ids of transactions, when they were
Break periods at the end of the month
SQL Server 2017 CREATE TABLE [TABLE_1] ( PLAN_NR decimal(28,6) NULL, START_DATE datetime NULL, ); INSERT INTO TABLE_1 (PLAN_NR, START_DATE) VALUES (1,’2020-05-01′), (2,’2020-08-01′); …
Selecting first and last time stamps of a section
I have a MySQL database with a table like: I would like to select from this table the first and last timestamp for each value of each Batch_Number. I would like the table to look like: I am not sure how to select both, when the previous Batch_Num is different from the curent one, and also when the next one
How to calculate percentage of availability using 2 sql query and combining it into result
I have to create a service availability using info from this 2 query. First Query. example result second query example result The formula as below ((Reporting Period – Unplanned Outage)/Reporting Period)*100 Answer Consider using conditional aggregation: The availability computation could probably be simplified:
Combine two different rows in single table using same table in SQL Server
Consider a database table holding data like that: Id UserId IsCheckIn DateTime Image AccountId 30356 60866 1 2020-12-19 12:17:17 b622f3e0806f.jpg 10017 30355 60866 0 2020-12-19 10:52:26 b622f3e0806f.jpg 10017 30354 60866 1 2020-12-19 10:51:02 b622f3e0806f.jpg 10017 30353 60866 0 2020-01-20 09:29:42 1596.jpg 10017 Desired output : Id UserId IsCheckIn InDateTime InImage AccountId IsCheckOut OutDateTime OutImage 30356 60866 1 2020-12-19 12:17:17 b622f3e0806f.jpg
MySQL convert timestamp and time string to DateTime format
In my table have two columns, one as timestamp to save the date and one as time string to save the time with period. Eg: I want to combine them into one column as DateTime format in the result then order by desc on that column. Here is the example: http://sqlfiddle.com/#!9/25eb21/4 The column name ‘Datetime’ expected is Datetime or timestamps
sql get balance at end of year
I have a transactions table for a single year with the amount indicating the debit transaction if the value is negative or credit transaction values are positive. Now in a given month if the number of debit records is less than 3 or if the sum of debits for a month is less than 100 then I want to charge
How can I select the max for a maths operation and also other elements without the max displaying all results
I am trying to find the maximum value of something, while also selecting other attributes at the same time. When i do the max statement on its own, it works as intended, but when I select another …
How to exclude rows with similar columns?
There is a table: | date | action | issue_id | | 2020-12-14 | close | 1 | | 2020-12-15 | close | 1 | | 2020-12-16 | close | 1 | | 2020-12-14 | close | 2 | …