Search
 
SCRIPT & CODE EXAMPLE
 

SQL

sql top 3 for each group

SELECT a.field1, a.field2
    FROM (
      SELECT field1, field2, ROW_NUMBER() --use RANK() if you want ranking
      over (Partition BY field_partition
            ORDER BY data_field DESC ) AS Rank
      FROM your_table
    ) a WHERE Rank <= 3 --Row Number you want of each group
Comment

PREVIOUS NEXT
Code Example
Sql :: using SQL in rails migration 
Sql :: order by multiple columns 
Sql :: sql example query 
Sql :: insert query in sql 
Sql :: read xml in sql server 
Sql :: mysql create table index 
Sql :: Write an SQL query to fetch worker names with salaries = 50000 and <= 100000. 
Sql :: dbms_metadata.get_ddl table 
Sql :: test sql query 
Sql :: oracle error compilation line 
Sql :: increment id in mysql 
Sql :: mysql add hours to time field 
Sql :: difference between normalization and denormalization 
Sql :: create table postgresql 
Sql :: postgres having 
Sql :: sql default value if null 
Sql :: 2nd highest value in sql 
Sql :: sql mode 
Sql :: sql row having max 
Sql :: dublicate row sql 
Sql :: sql set data from a select query to a temp table and insert 
Sql :: sql table backup 
Sql :: sql unique 
Sql :: how to find table lock and row lock in mysql 
Sql :: mysql trigger 
Sql :: unique key in sql 
Sql :: oracle ora-00054 how to unlock 
Sql :: sum row in sql 
Sql :: show database not empty tables postgres 
Sql :: psql command not found windows 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =