New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Limit or First x but by group [CORE2689] #1142
Comments
Modified by: Ivan (patuljak)description: first n is include in sql statement but if I want selected first n records for each group which is in group by clause I need usig row_number() over (partition by ) CREATE TABLE employees ( CREATE TABLE departments ( CREATE TABLE emp_dep ( select emp_dep.date_of_insert, emp_dep.mytime, t3.department_name , t2.employee_name from employees t2,departments t3,emp_dep for first 3 or => first n is include in sql statement but if I want selected first n records for each group which is in group by clause I need usig row_number() over (partition by ) CREATE TABLE employees ( CREATE TABLE departments ( CREATE TABLE emp_dep ( select emp_dep.date_of_insert, emp_dep.mytime, t3.department_name , t2.employee_name from employees t2,departments t3,emp_dep for first 3 or with one or more parameters for limit or first. |
Commented by: Ivan (patuljak) ok, then close. |
Modified by: @pcisarstatus: Resolved [ 5 ] => Closed [ 6 ] |
Submitted by: Ivan (patuljak)
Is replaced by CORE1688
first n is include in sql statement but if I want selected first n records for each group which is in group by clause I need usig row_number() over (partition by )
but I don't if firebird support row_number(other database support this)
CREATE TABLE employees (
employee_id integer PRIMARY KEY,
employee_name text
)
CREATE TABLE departments (
department_id integer PRIMARY KEY,
department_name text
)
CREATE TABLE emp_dep (
ID_employee integer,
ID_department integer,
date_of_insert date default NOW(),
mytime time default NOW(),
PRIMARY KEY(ID_employee, ID_department)
)
select emp_dep.date_of_insert, emp_dep.mytime, t3.department_name , t2.employee_name from employees t2,departments t3,emp_dep
where emp_dep.ID_employee=t2.employee_id and emp_dep.ID_department=t3.department_id
group by emp_dep.date_of_insert,t3.department_name , t2.employee_name, emp_dep.mytime
order by emp_dep.date_of_insert desc, emp_dep.mytime desc
limit by group(t3.department_name,3)
for first 3
or
select first 3 by group(t3.department_name) emp_dep.date_of_insert, emp_dep.mytime, t3.department_name , t2.employee_name from employees t2,departments t3,emp_dep
where emp_dep.ID_employee=t2.employee_id and emp_dep.ID_department=t3.department_id
group by emp_dep.date_of_insert,t3.department_name , t2.employee_name, emp_dep.mytime
order by emp_dep.date_of_insert desc, emp_dep.mytime desc
with one or more parameters for limit or first.
The text was updated successfully, but these errors were encountered: