Skip to content
Advertisement

Tag: postgresql

How can I get last 2 records from another table as columns

I have a table called products with this schema: And another table with fee change log with this schema: Is there anyway to get last 2 fee changes for each sku in one sql and not 2 rows for each sku, I want to have 2 new columns with old_fee_1, new _fee_1, old_fee_2, new_fee_2: Desired result: dbfiddle Answer As starting

How to use between if value is not null?

Im trying to write query where im using valid_from and valid_to but those values can be null or one of them. This is my query, so i want to return data using if both valid_from and valid_to is null, or both not null or only valid_to is null. Any suggestion how can i achive that? Answer You could just explicitly

How to use ANALYZE EXPLAIN in a with_something query

I’m trying to find out how to use ANALYZE EXPLAIN on my PSQL query. If I add ANALYZE EXPLAIN SELECT, I get a syntax error. I have no clue how to use it. I added the ANALYZE before the first and second SELECT, but both throw a syntax error. I was unable to find different examples but on documentation, I

translate query from Oracle to Postgres

I need to translate this query from Oracle to Postgres: can someone help me? thanks in advance for your attention and support Answer In postgres the operateur ~ performs a regex comparison as thus replaces the Oracle function regexp_like(). Your query therefore becomes. I would like to alert your attention that the test not upper(location) ~ ‘^[0-9]{1,5}.* [a-z]’ will always

Grouping by multiple columns in a range in postgres

I have a couple tables (pega.race exists too we just don’t need any of the data for this) What I want is to get an average result for each combination (permutation?) of speed/strength/wind/lightning/water/fire in a range. So from 0-2.25, 2.25-4.5, 4.5-6.75, and 6.75-9. They have to be within 0-9. No values exist outside that. So I want an avg result

Postgres: Where value equal decimal value

My table looks like this: When the WHERE clause is equal to value with decimal point I get no valid output like: Output: transponder_id = None When the query is for integer value, query works correctly: Output: transponder_id = 1009 Also using BETWEEN query returns expected values Output: transponder_id = 1010 Why is my query using ‘equal’ operator not working

Advertisement