Skip to content

Window Function for First Instance in Repeating Time Periods

I’m trying to translate the logic below into one or more SQL statements: Find the first occurrence of a given event for a user If the user has any additional events on that day or 30 days after, exclude those events. Keep only the first event. 30 days after the original event, you may consider new events, but the original

How can i change SQL date format to: 12th Jun 2021. (as example)

So, I’m trying to insert data from .csv file, but because of the date format I’m using – import causes it to set to 00-00-0000 import settings: format – CSV using load data (otherwise it causing errors and failing to import) Specific format options: none Errors I’m receiving after import: Data truncated for column… my_date sets to 0000-00-00, even with

Combine rows by consecutive timestamp

I have an input table as below: name time price one 2022-11-22 19:00:00 UTC 12 one 2022-11-23 7:00:00 UTC 24 one 2022-11-23 19:00:00 UTC 10 one 2022-11-24 7:00:00 UTC 20 My expected output is: name time price one 2022-11-22 36 one 2022-11-23 30 Explanation: I have to group-by 2 consecutive timestamps, the prev date 19:00:00 UTC and the next date

how join laravel tables to get non intersected data

in my Laravel app I have 3 tables : users, documents and type_documents, the user have multiple documents and document have one type_document I want select the types that are not used in documents table for the current user with eloquent I try with this, but it give me the used type_documents : I use Laravel version 8 Answer Have

Update statement with inner join on Oracle ORA-01427

ORA-01427: single-row subquery returns more than one row ORA-06512: at “SYS.DBMS_SQL”, line 1721 I need to do update with inner join in ORACLE Answer The script you provided above is going to update all rows in the table because you do not have a where clause. If you really want to update all rows in the table, then this should

SQL: Flattening multiple rows in ugly data

I’m working on a fairly odd scenario in which I’ve got to compensate for a client’s database that isn’t very well-ordered. The data (example below) concerns some products that have a main serial number (serial) and between 0 and 4 additional alternate serials (alt_serial). Unfortunately, neither of these columns is a primary key, and each alternate serial number produces an

Alter Table Foreign Key

I’m trying to add barista_grade_id to the baristas table as a foreign key and I’ve looked every where on what syntax to use and it seems to be unanimous that this is the correct way. I did it before this and it worked. but because of some mistakes I deleted it and redo it again, but for whatever reason it