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: List all the load shapes of all head cars of each train and identify which load shape has the highest number. Calculate the percentage of the trains with the said head car that are running eas
Evidence: which load shape has the highest number refers to MAX(load_shape); head car refers to position = 1; east is a direction; calculation = MULTIPLY(DIVIDE(count(direction = 'east' where MAX(load_shape) where position = 1 then id), count(id)), 100)

SQL:
SELECT DISTINCT T3.load_shape FROM ( SELECT load_shape, train_id FROM cars WHERE position = 1 ORDER BY train_id DESC ) AS T3 UNION ALL SELECT T4.load_shape FROM ( SELECT load_shape, train_id FROM cars WHERE position = 1 ORDER BY train_id DESC LIMIT 1 ) AS T4 UNION ALL SELECT (CAST(COUNT(DISTINCT CASE WHEN T2.direction = 'east' THEN T2.id ELSE NULL END) AS REAL) * 100 / COUNT(DISTINCT T2.id)) FROM cars AS T1 INNER JOIN trains AS T2 ON T1.train_id = T2.id WHERE T1.position = 1 AND T1.load_shape = ( SELECT T4.load_shape FROM ( SELECT load_shape, train_id FROM cars AS T WHERE position = 1 ORDER BY train_id DESC LIMIT 1 ) AS T4 )