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, …

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 …

Get rows with a condition

Each customer can have one or multiple accounts (account_id) How can I get max closed_date for the customers who closed all their accounts and the rest of the active customers?* *active customers are …

postgres sql query to convert group by result in multiple columns

I have two tables financial_account having columns account_name financial_transaction having columns transaction_date,transaction_type, transaction_amount I need data as SUM(transaction_amount) …

SQL query is only returning one entry, when it should be returning several

I am creating a book tagging system and I am trying to call all the books with the same tag. My query is only turning up the first book, and not any of the following books with the same tag. Here is …