I’m pretty new to Postgres and SQL as a whole and could use a bit of help with a function here. I have this table: What i need is for a function to take as input plate, start date and end date and throw an error if the table contains any row with the same plate where the rental period
Tag: sql
Method returns a value but the property does not hold it
The method LocalizaArquivo() calls the method VerificaArquivoCarregado() that checks if the file is already loaded. If it is loaded returns arquivoCarregado = true. When I debug it, I can see that arquivoCarregado = true, but after the method VerificaArquivoCarregado() is finished it changes to false. The pro…
How do I use a prior query’s result when subtracting an interval in Postgres?
I have the following code: How do I use example_var in in the interval? I’d like to do something like – interval CONCAT(example_var, ‘day’) so that I could change what example_var is equal to and therefore change the length of interval but that isn’t working. Answer If you want t…
MySQL Merge two queries based on mutual column
I have two queries that retrieve records from 2 different tables that are almost alike and I need to merge them together. Both have created_date which is of type datetime and I’m casting this column to date because I want to group and order them by date only, I don’t need the time. First query: Se…
Oracle display number of unique values for column combination
I have the below table C1 C2 C3 A1 A2 A3 B1 B2 B3 C1 C2 C3 C1 C4 C3 For each unique combination of C1 and C3, I would like to keep the first value in C2, but storing the count of unique elements …
Incorrect parameter count in the call to native function ‘str_to_date’
There is a table tab1: |creation_date | acc_num | status| |——————-|———————|——-| |31.03.2021 07:43:43| 11111111111111111111| deny | |31.03.2021 07:43:43| …
Postgresql – access/use joined subquery result in another joined subquery
I have a database with tables for equipment we service (table e, field e_id) contracts on the equipment (table c, fields c_id, e_id, c_start, c_end) maintenance we have performed in the past (table m,…
window function rolling sum
I have a window function that gives me a rolling sum as below: but when some timestamps in the start_time column are equal the rolling sum stays the same, which makes sense bc I am ordering by start time, but it does not properly add the duration_seconds in the rolling sum as below: how can i fix or account f…
Calculate the number of unique strings with the date, with a possible error
In the select, I get rows from the table with time in the format TIMESTAMP. I want to count unique rows, BUT with a possible error of 1 second. In the example below, for example, 3 unique records (1 …
Determine persistent growth in value during a specific time range
Given the following data set example, how should I structure my SQL query to determine if the value has gradually grown day-by-day given a time range in the query for a specific user_id by returning a …