Skip to content

How to join in SQL-SERVER

I am trying to learn SQL-SERVER and I have created the below query: WITH T AS ( SELECT ROW_NUMBER() OVER(ORDER BY d.DIALOG_ID) as row_num, * FROM test.db as d INNER JOIN test.dbs as ds …

Correct way to implement nested aggregation in PostgreSQL

I have a table that looks something like this: Multiple foo_id can belong to bar_id, and multiple timestamp can belong to foo_id What I want to do is to count the number of foo_id and the average length of foo_id (i.e. timestamp difference between the last and the first instance of the foo_id), belonging to t…

How to find parent row for same table

I have table something like this: childId | parentId 1 | null 2 | 1 3 | null 4 | 2 Column childId is primary key of this table and parentId is foreign key to same this …

Pick relevant value in a set of columns

It might be an easy question for DBA, but not for me. I have a simplified Family table that looks like that: (part1 and part2 are ids) famid indiv1 indiv2 1 42 27 2 33 22 3 42 12 4 22 42 5 42 27 …

Regarding SQL Inner Join [closed]

Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 2 years ago. Improve this question The question is as follows : My question is regarding SQL code for the following question. F…