SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
create table depart ( id int primary key, dep varchar(255)); create table students( id int primary key, name varchar(255), dep int, mark int, foreign key (dep) references depart(id)); insert into depart values (1, 'math'), (2, 'other'); insert into students values (1, 'i', 1, 5), (2, 'he', 2, 5), (3, 'he', 1, 3), (4, 'i', 1, 2), (5, 'i', 1, 2); select name, avg(mark) from students s join depart d on d.id = s.dep where d.DEP like 'math' group by name order by avg(mark)

Stuck with a problem? Got Error? Ask ChatGPT!

Copy Clear