Database schema:

CREATE TABLE cars (
	id INTEGER NOT NULL -- example: ['2', '1'],
	train_id INTEGER DEFAULT NULL -- example: ['2', '1'],
	position INTEGER DEFAULT NULL -- example: ['2', '1'],
	shape TEXT DEFAULT NULL -- example: ['rectangle', 'bucket'],
	len TEXT DEFAULT NULL -- example: ['long', 'short'],
	sides TEXT DEFAULT NULL -- example: ['not_double', 'double'],
	roof TEXT DEFAULT NULL -- example: ['none', 'peaked'],
	wheels INTEGER DEFAULT NULL -- example: ['2', '3'],
	load_shape TEXT DEFAULT NULL -- example: ['hexagon', 'circle'],
	load_num INTEGER DEFAULT NULL -- example: ['1', '3'],
	PRIMARY KEY (id), 
	CONSTRAINT fk_cars_trains FOREIGN KEY(train_id) REFERENCES trains (id)
)


CREATE TABLE trains (
	id INTEGER NOT NULL -- example: ['2', '1'],
	direction TEXT DEFAULT NULL -- example: ['west', 'east'],
	PRIMARY KEY (id)
)

Question: Among the trains running west, how many trains have no more than one car with an open roof?
Evidence: running west refers to direction = 'west'; open roof refers to roof = 'none'

SQL:
SELECT SUM(CASE WHEN T1.direction = 'west' THEN 1 ELSE 0 END)as count FROM trains AS T1 INNER JOIN ( SELECT train_id, COUNT(id) FROM cars WHERE roof = 'none' GROUP BY train_id HAVING COUNT(id) = 1 ) AS T2 ON T1.id = T2.train_id