SQLize Online / PHPize Online  /  SQLtest Online

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

Stuck with a problem? Got Error? Ask ChatGPT!

Copy Clear