Hi! Could we please enable some services and cookies to improve your experience and our website?

SQLize | PHPize | SQLtest

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

A A A
Login    Share code      Blog   FAQ
Copy Format Clear
create table Clients ( ClientId int primary key auto_increment, ClientFirstName varchar(64), ClientLastName varchar(64), ClientDoB date, Occupation varchar(64) ); insert into Clients (ClientFirstName, ClientLastName, Occupation) values ('John', 'Smith', 'bookkeper'), ('Sarah', 'Connor', 'doctor'); create table Borrower ( BorrowId int primary key auto_increment, ClientId int, BookId int, BorrowDate date, index(ClientId), foreign key (ClientId) references Clients(ClientId) ); insert into Borrower (ClientId, BookId) values (1, 1), (1, 2), (1, 3), (2, 1), (2, 7); SELECT Occupation, count(*) BooksBorrowed FROM Borrower NATURAL LEFT JOIN Clients GROUP BY Occupation;

Stuck with a problem? Got Error? Ask AI support!

Copy Clear