Skip to content
Advertisement

Tag: postgresql

SQL write a query, question from interview problem

At the beginning I need to mention that I am not very good at SQL so I would like to ask you. Here is a tables relation: tables What I need to do with them is “Show name, surname and number of movies those directors (Reżyser means director), who made more movies that the average number is for all directors.

Add a number for duplicate values in posgresql

I’ve a query in MySQL and I’m looking for a query which can perform below operation using Posgres MySQL Query : Output: Email Row Number Aamir 1 Aamir 2 Aamir 3 Suresh 1 Suresh 2 Hafiz 1 Answer https://www.db-fiddle.com/f/3RqNHRGFjkU74v33upyfhi/0

how to get json result to fixed number by grouping in postgresql?

I want to get expected results to one query execution. the “where” clause should one value. so I can’t use this query as sub-query of main-query. could you tell me how to do it? Sample sql query: Expected results: results [{“id”:1,”name”:”hello”},{“id”:4,”name”:”good”},{“id”:7,”name”:”world”}, {“id”:9,”name”:”happy”}] [{“id”:10,”name”:”funny”},{“id”:12,”name”:”stack”},{“id”:15,”name”:”queue”},{“id”:18,”name”:”map”}] [{“id”:19,”name”:”list”},{“id”:23,”name”:”code”}] Answer demo: db<>fiddle Convert your records into JSON objects Create a row count using the row_number()

Full Outer Join failing to return all records from both tables

I have a pair of tables I need to join, I want to return any record that’s in tableA, tableB or both. I think I need a FULL OUTER JOIN This query return 1164 records And this one return 3339 records And this one returns 3369 records (so there must be 30 records in tableA that aren’t in tableB) I

Enforce 2 unique constraints on upserts in Postgres

I have a table where I save contacts data I add data to this table from several sources. Some sources have Linkedin profiles data about people, other sources have email data. Sometimes the full names are not equal, even if they refer to the same person. And I want to do upserts to not have duplicated data. For now I’m

PSQL: How to compare record to previous record (2 tables)?

I have two tables: 01_System_Log Records I need to create a view, where the records of the last request id (3) are compared with the previous (2). So far I made a view, where the most actual records are shown. I am not sure how to proceed, while in all compare examples, which I have found, only one table was

Advertisement