Как решить mysql более 15 подзапросов "ошибка подзапроса возвращает более 1 строки"

-4

SELECT et.*,
(SELECT el.waitTime FROM entityleg as el WHERE et.tripId=el.tripId LIMIT 1) AS leg1_waittime,
(SELECT el.mode FROM entityleg as el WHERE et.tripId=el.tripId LIMIT 1) AS leg1_mode,
(SELECT el.time FROM entityleg as el WHERE et.tripId=el.tripId LIMIT 1) AS leg1_time,
(SELECT el.fare FROM entityleg as el WHERE et.tripId=el.tripId LIMIT 1) AS leg1_fare,
(SELECT el.waitTime FROM entityleg as el WHERE et.tripId=el.tripId LIMIT 1,1) AS leg2_waittime,
(SELECT el.mode FROM entityleg as el WHERE et.tripId=el.tripId LIMIT 1,1) AS leg2_mode,
(SELECT el.time FROM entityleg as el WHERE et.tripId=el.tripId LIMIT 1,1) AS leg2_time,
(SELECT el.fare FROM entityleg as el WHERE et.tripId=el.tripId LIMIT 1,1) AS leg2_fare,
(SELECT el.waitTime FROM entityleg as el WHERE et.tripId=el.tripId LIMIT 1,2) AS leg3_waittime,
(SELECT el.mode FROM entityleg as el WHERE et.tripId=el.tripId LIMIT 1,2) AS leg3_mode,
(SELECT el.time FROM entityleg as el WHERE et.tripId=el.tripId LIMIT 1,2) AS leg3_time,
(SELECT el.fare FROM entityleg as el WHERE et.tripId=el.tripId LIMIT 1,2) AS leg3_fare,
(SELECT el.waitTime FROM entityleg as el WHERE et.tripId=el.tripId LIMIT 1,3) AS leg4_waittime,
(SELECT el.mode FROM entityleg as el WHERE et.tripId=el.tripId LIMIT 1,3) AS leg4_mode,
(SELECT el.time FROM entityleg as el WHERE et.tripId=el.tripId LIMIT 1,3) AS leg4_time,
(SELECT el.fare FROM entityleg as el WHERE et.tripId=el.tripId LIMIT 1,3) AS leg4_fare
FROM entitytrip as et

спросил(а) 2016-05-13T11:03:00+03:00 4 года, 1 месяц назад
0
78

SELECT et.*,
(SELECT el.waitTime FROM entityleg as el WHERE et.tripId=el.tripId LIMIT 1) AS leg1_waittime,
(SELECT el.'mode' FROM entityleg as el WHERE et.tripId=el.tripId LIMIT 1) AS leg1_mode,
(SELECT el.'time' FROM entityleg as el WHERE et.tripId=el.tripId LIMIT 1) AS leg1_time,
(SELECT el.fare FROM entityleg as el WHERE et.tripId=el.tripId LIMIT 1) AS leg1_fare,
(SELECT el.waitTime FROM entityleg as el WHERE et.tripId=el.tripId LIMIT 1,1) AS leg2_waittime,
(SELECT el.'mode' FROM entityleg as el WHERE et.tripId=el.tripId LIMIT 1,1) AS leg2_mode,
(SELECT el.'time' FROM entityleg as el WHERE et.tripId=el.tripId LIMIT 1,1) AS leg2_time,
(SELECT el.fare FROM entityleg as el WHERE et.tripId=el.tripId LIMIT 1,1) AS leg2_fare,
(SELECT el.waitTime FROM entityleg as el WHERE et.tripId=el.tripId LIMIT 2,1) AS leg3_waittime,
(SELECT el.'mode' FROM entityleg as el WHERE et.tripId=el.tripId LIMIT 2,1) AS leg3_mode,
(SELECT el.'time' FROM entityleg as el WHERE et.tripId=el.tripId LIMIT 2,1) AS leg3_time,
(SELECT el.fare FROM entityleg as el WHERE et.tripId=el.tripId LIMIT 2,1) AS leg3_fare,
(SELECT el.waitTime FROM entityleg as el WHERE et.tripId=el.tripId LIMIT 3,1) AS leg4_waittime,
(SELECT el.'mode' FROM entityleg as el WHERE et.tripId=el.tripId LIMIT 3,1) AS leg4_mode,
(SELECT el.'time' FROM entityleg as el WHERE et.tripId=el.tripId LIMIT 3,1) AS leg4_time,
(SELECT el.fare FROM entityleg as el WHERE et.tripId=el.tripId LIMIT 3,1) AS leg4_fare
FROM entitytrip as et

Вот скорректированный код. Поскольку время и режим уже предопределены в mysql. Поэтому для того, чтобы mysql понимал его как имя столбца, вы должны использовать `time` и` mode`.

Также произошла ошибка "подзапрос возвращает более 1 строки", так как вы неправильно установили лимит и смещение. Вместо limit 2,1 вы использовали limit 1,2. Аналогично, limit 3,1 вы использовали limit 1,3

ответил(а) 2016-05-13T11:30:00+03:00 4 года, 1 месяц назад
40

Не пытаясь понять, что вы хотите сделать, я вижу, что последние 8 подзапросов имеют ограничение 1,2 или 1,3. Эти подзапросы вернут более одной строки, чтобы вы лучше изменили ее на 2,1 и 3,1

SELECT et.*,
(SELECT el.waitTime FROM entityleg as el WHERE et.tripId=el.tripId LIMIT 1) AS leg1_waittime,
(SELECT el.mode FROM entityleg as el WHERE et.tripId=el.tripId LIMIT 1) AS leg1_mode,
(SELECT el.time FROM entityleg as el WHERE et.tripId=el.tripId LIMIT 1) AS leg1_time,
(SELECT el.fare FROM entityleg as el WHERE et.tripId=el.tripId LIMIT 1) AS leg1_fare,
(SELECT el.waitTime FROM entityleg as el WHERE et.tripId=el.tripId LIMIT 1,1) AS leg2_waittime,
(SELECT el.mode FROM entityleg as el WHERE et.tripId=el.tripId LIMIT 1,1) AS leg2_mode,
(SELECT el.time FROM entityleg as el WHERE et.tripId=el.tripId LIMIT 1,1) AS leg2_time,
(SELECT el.fare FROM entityleg as el WHERE et.tripId=el.tripId LIMIT 1,1) AS leg2_fare,
(SELECT el.waitTime FROM entityleg as el WHERE et.tripId=el.tripId LIMIT 2,1) AS leg3_waittime,
(SELECT el.mode FROM entityleg as el WHERE et.tripId=el.tripId LIMIT 2,1) AS leg3_mode,
(SELECT el.time FROM entityleg as el WHERE et.tripId=el.tripId LIMIT 2,1) AS leg3_time,
(SELECT el.fare FROM entityleg as el WHERE et.tripId=el.tripId LIMIT 2,1) AS leg3_fare,
(SELECT el.waitTime FROM entityleg as el WHERE et.tripId=el.tripId LIMIT 3,1) AS leg4_waittime,
(SELECT el.mode FROM entityleg as el WHERE et.tripId=el.tripId LIMIT 3,1) AS leg4_mode,
(SELECT el.time FROM entityleg as el WHERE et.tripId=el.tripId LIMIT 3,1) AS leg4_time,
(SELECT el.fare FROM entityleg as el WHERE et.tripId=el.tripId LIMIT 3,1) AS leg4_fare
FROM entitytrip as et

ответил(а) 2016-05-13T11:07:00+03:00 4 года, 1 месяц назад
Ваш ответ
Введите минимум 50 символов
Чтобы , пожалуйста,
Выберите тему жалобы:

Другая проблема