Skip to content

Tag: sql

Select only the records with same values

I am working on a SQL statement that will become a part of a view. What I need is to extract only the records that have the same unique key twice. The query looks like below right now. The result I get from the query above is: I need to modify the SQL statement so that the end result is

Select max date per year

I have the table as follows: And I’d like to select the max date for every year per user, so the result would be like: Some help? Thank you! Answer Just use aggregation: If you have more columns that you want, then use distinct on:

SQL AVG applied to more than one by group?

I am trying to calculate a column average by group for several groups in the same query. Assume there are 2 columns (a,b), for each I want the average of another column (c) per group of the first column. For example, this would return the a groups and average c value per a group. This gives me two columns. a