### Database Schema:
CREATE TABLE trains (
	id	INTEGER	NOT NULL	PRIMARY KEY,
	direction	TEXT	NULL	DEFAULT NULL
);

CREATE TABLE cars (
	id	INTEGER	NOT NULL	PRIMARY KEY,
	train_id	INTEGER	NULL	DEFAULT NULL,
	position	INTEGER	NULL	DEFAULT NULL,
	shape	TEXT	NULL	DEFAULT NULL,
	len	TEXT	NULL	DEFAULT NULL,
	sides	TEXT	NULL	DEFAULT NULL,
	roof	TEXT	NULL	DEFAULT NULL,
	wheels	INTEGER	NULL	DEFAULT NULL,
	load_shape	TEXT	NULL	DEFAULT NULL,
	load_num	INTEGER	NULL	DEFAULT NULL,
	foreign key (train_id) references trains (id)
);

### User's Query:
How many cars on a train that runs in the east direction have a flat roof?

### Extra Knowledge:
flat roof refers to roof = 'flat'
SELECT SUM(CASE WHEN T1.roof = 'flat' THEN 1 ELSE 0 END)as count FROM cars AS T1 INNER JOIN trains AS T2 ON T1.train_id = T2.id WHERE T2.direction = 'east'