Including only one row in sql [closed]

What I’m trying to do is take these records that looks like this: ID NAME STARTDATE ENDDATE EnrollmentMonth 1 PETER 20200705 20200729 20200701 1 TONY 20200730 99991231 …

Get the logs of the current week in postgresql

I need to get the logs of the current week in postgresql, I have tried to use the native mysql functions yearweek for that, but here in postgresql it is different This is my table CREATE TABLE …

PostgreSQL, summing multiple date columns over multiple rows

Let’s assume the following table: CREATE TABLE assumption ( datetime_1 TIMESTAMP, datetime_2 TIMESTAMP, datetime_3 TIMESTAMP); Now I want to know the total amount of times a month is set in any row …

Date distinct count over week

Im trying to get a distinct count of user ids logs per day with every week as a partition for the distinct identification. e.g. if one user logs on Friday/Saturday of week 1, and on Monday/Friday of …

SQl Query to get an output that resembles the image [closed]

I would like to get output the way its shown in the image attached and the way the input is organized is also shown in the image attached. Thanks!

Postgres: how to check for records in time buckets for multiple values

I have a POSTGRES table with roughly the following shape: sensor_id | recorded_at ———-+——————– A | 2020-01-01 00:00:00 A | 2020-01-01 00:03:00 B | …

MySql select all records from the table with month and year in the range from that month and year to all the past [closed]

I have a table with two fields “month” and “year” how can I make a query that, passing a month and a year, select everything from that month and year back. For example, if the …

Only include values from the latest timestamp into the query result

DB-Fiddle CREATE TABLE sales ( id int auto_increment primary key, time_stamp TIMESTAMP, product VARCHAR(255), sales_quantity INT ); INSERT INTO sales (time_stamp, product, …

Max and Avg debt days over a period of time

I have invoices pending payment, every invoice has two dates, first when the invoice is required to pay and the other when the invoice is paid. I want to know in a period of time the max debt and the …

Grouping shift data by 7-day windows in SQL Server 2012

What I want to do is to calculate the number of shifts and hours worked by each employee in any given 7-day period. In order to achieve this, I need to identify and group ‘islands’ of shifts. Note …