Skip to content
Advertisement

Category: Questions

Select distinct values by key from JSONB column

Postgres v12.0 I have a table data {“a”: “1”, “b”: “1”} {“a”: “2”, “b”: “1”} And I’d like to retrieve a distinct list of keys and the set of values for each key key values a [ “1”, “2” ] b [ “1” ] Not sure how to formulate a query to achieve those results. Answer here is one way:

Outsystems Advanced SQL

I will start by introducing my business logic. I have an entity called Machines. To each Machine I will assign up to 50 Options. On this query I used PIVOT so I can retrieve only one line per machine, with all the options (Columns) with value 0 or 1. Note: My Output structure is ready for 50 Options. SQL Query

SQL INNER JOIN of sum distinct values

I have 3 tables called musics, singers and playlistInfos. I want to get Top 10 listened England musics.What kind of sql query help me? SELECT * FROM musics m INNER JOIN playlistInfo p ON p.musicID = m.id INNER JOIN singer a ON a.id = m.singerID GROUP BY p.musicID ORDER BY p.listened I try this one but I did not get

How do I size and sapce

this is what i needed and i appreciate it guys Answer For problems like these, try to associate the output with its indices (or in this case, current_row). Also, it seems like it’s better to start from 0 for this one. max_row is 5, current_row is from 0 to 4. There are max_row – current_row – 1 spaces on each

SQL query to count how many values appear N times in a column

I have a table like this, but with 1mi rows: And I want to know how many TEAMS were visited N times. For instance, if I want to know how many TEAMS were visited once, the result would be 1 (because only team 2 was). If i wanted three times, result would be 2 (because both team 1 and 4

SQL query to find gaps within a column of dates

I have a table with status and date for every day and I’m trying to find out when the statuses change and if there’s gaps within each status change / how many days were of a certain status. Expected output: Answer This is a type of gaps-and-islands problem. In this case, subtracting a sequential number from each day is probably

Advertisement