SQL query filter down to only applicable rows

How would I select a query like this? I am a bit confused because this would return nothing since any of the rows do not fulfill any of the “where clauses”.. What I would like is the answer …

Get previous months first and last date

I need to query last month data from a database. So I need the first and last date of previous month to be able to make the “between” SQL query. First date starts always from 1 of course, …

Postgres comparing strings from json and table

I have the following postgres stored function: CREATE OR REPLACE FUNCTION wg.get_user( req jsonb) RETURNS jsonb LANGUAGE ‘plpgsql’ COST 100 VOLATILE AS $BODY$ DECLARE …

Use rownum to indicate what rows I have pulled back

I have table of people, with firstname and lastname. firstname lastname a a b b c c d d e e f f g g h h i i j j I want to query from a specific point. For example. SELECT FIRSTNAME, …

Why I get division by zero for PostgreSQL v13? I suppose rows should be filtered out

Running same query on different versions of PostgreSQL gives different result. WITH t(a, b) AS (VALUES (1, 0)) SELECT a / b FROM t WHERE b 0; On v11.10 I get no rows as expected fiddle On …

How to have different values of a single column in a condition where in sql?

I write a SQL query to get different sales information about stores. The problem is that I would like to filter and take only some store numbers in my “GL_ETABLISSEMENT” column, if I just do …

How to fix my postgres function syntax to fit a user parameter

I’m trying to make a postgreql function, I’m a little confused on which syntax format to use when I’m passing a select statement that takes in a parameter (this parameter can be a string or a list of …

using case statement in a where clause

Hello I am missing something because my code errors. select * from ##ScheduleDetail SD left join ##HolidayFilterTbl HF on SD.Scheduledate = HF.Testdate where (ScheduleDate = testdate) and (Case …

filter timestamp column in SQL Oracle

I have a table with a Timestamp column which I need to filter after ‘2020-08-26’, but every solution won’t work RUN_TIME 2020-07-22 04:22:07 2020-07-22 04:34:07 2020-07-22 04:45:07 2020-07-22 04:50:07 …

How to speed up sql query execution?

The task is to execute the sql query: select * from x where user in (select user from x where id = ‘1’) The subquery contains about 1000 id so it takes a long time. Maybe this question was already …