Among the trains that run in the east direction, how many of them have more than 2 long cars?
more than 2 long cars refers to longCarsNum > 2
SELECT SUM(CASE WHEN T2.longCarsNum > 2 THEN 1 ELSE 0 END)as count FROM trains AS T1 INNER JOIN ( SELECT train_id, COUNT(id) AS longCarsNum FROM cars WHERE len = 'long' GROUP BY train_id ) AS T2 ON T1.id = T2.train_id WHERE T1.direction = 'west'
CREATE TABLE `cars` (
  `id` INTEGER NOT NULL,
  `train_id` INTEGER DEFAULT NULL,
  `position` INTEGER DEFAULT NULL,
  `shape` TEXT DEFAULT NULL,
  `len`TEXT DEFAULT NULL,
  `sides` TEXT DEFAULT NULL,
  `roof` TEXT DEFAULT NULL,
  `wheels` INTEGER DEFAULT NULL,
  `load_shape` TEXT DEFAULT NULL,
  `load_num` INTEGER DEFAULT NULL,
  PRIMARY KEY (`id`),
  FOREIGN KEY (`train_id`) REFERENCES `trains` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE `trains` (
  `id` INTEGER NOT NULL,
  `direction` TEXT DEFAULT NULL,
  PRIMARY KEY (`id`)
);
