Skip to content
Advertisement

Tag: postgresql

LIMIT and OFFSET returning repeating results

There seems to be a bug in my query that causes results to repeat when I increment the OFFSET value. It is supposed to show 20 results per page. Only 3 results match what my query is looking for, but for some reason, some of these results repeat themselves even though they should only appear on the first page of

Calculating win streak from list of fixtures

I have a table fixtures with a list of matches played between two players in each, identified by their ID. I’m trying to use the table to calculate rolling winning/losing streaks for each player, but I’ve been having issues with my query below (see more on SQL Fiddle): Below is the desired result, with records partitioned by player_id and ordered

Based on previous records, stop sum fields

I have a table like this: My goal is to obtain sum of points from date now to date that the point is greater than equal to 1 and stop sum of fields before that date. In the example above (order by date), the answer is sum of points date now(2022/01/06) to the date 2022/01/04 and equals 9 + 7

Postgres Timestamp to DATE dd-mm-yyyy

im trying to insert select a casted timestamp in a date colum timestamp like 02-09-2021 00:00:00, and i need to convert this timestamp to date dd-mm-yyyy without hhmmss, i’ve tried select date(column) as newdate but when i check my table insert, it keeps like timestamp, all the solutions that i tried only runs perfectly only in a select sentence, but

Using IF in PostgreSQL

I need to check (here for an example) if the average earnings of DE workers are higher than IT workers. I tried using but it doesn’t seem to work. Is there any way to do this in PostgresSQL (I am using version 14) first_name last_name country earnings Andrea Pfeiffer DE 800 Eufrosina Marchesi IT 2975 Elisa Sabbatini IT 2450 Marco

Get rows whose JSON array contains an object with a value

I have a query that returns one JSON column named record, which is generated by a subquery. SELECT record FROM (my json query) records; Each record contains an array of tag objects: I want to modify my query to select all records where tags contains a tag with a specific ID but I’m not sure how to go about that

How to count NULL in COUNT(column) query?

I have the following table that I’m trying to find the total count for each unique name element. The problem is, other: 1 and other: Null are supposed to be different elements, but my query is grouping them together. The issue I’m running into is that null is not being counted as a row. But when I use count(*), other:

Postgresql merge columns

I have a main table which is like this I can merge full_name and last_name like this but I couldn’t do the same thing with the children_names column I want to select children like this but I want to add last_name filed at the end of each child like this Answer Using a scalar subquery: Yet it would be much

Trim Intermediate spaces in a string in Postgres

In the result, want only intermediate spaces to be removed. Need to print only first part before hypen (-) along with Percentages. Can you please help. Input String: AMAZON – 25%; SAP – XXXXX – 45%; MICROSOFT – XXX&YYY – 30% Query: Answer regexp_split_to_table can be used to split the value into strings by the delimiter ;, then you can

Advertisement