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”…
Tag: sql
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 Quer…
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 n…
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 –…
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 n…
Using subquery with update SQL
I have Table 1 : EMP as below Table 2: EMP1 ID is the Key and is common in both the files. I want an Update SQL to update the amount field of Table 1 using Amount field of table 2, which gives the result as below. Result: Answer One method is a correlated subquery: You can check if the
Data from 2 tables is not displaying on the same page
I’m a newbie in PHP and mySQL, I’m currently working on a profile page where I will display the logged in user’s personal information from one table called users and also display the tours that they will book in the future from my website from this table: booking I’m fetching the data …
How to check how many issues are opened daily in SQL
I have data from issues in a table with the following schema. I want to know how many issues are open every day using PostgreSQL. We consider an issue being open at date x if: x >= created_at x <= deleted_at There may be days where no issues were created or deleted, as in the example. How can I do
What’s the equivalent syntax in MySQL for selecting date ranges by YEAR based on MSSQL syntax?
I have a MSSQL syntax to select date within 2 years: This works fine, column_1 only return date within two years of the given date. However, I’m trying to convert it to MySQL syntax, here’s what I have tried: But this returns dates not only within two years range but also other years, am I missing…