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
-1
A
答えて
0
最後の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
0
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がカラム名として解釈するには、`時間`と`モード`を使用する必要があります。
また、制限とオフセットを間違って配置したため、「サブクエリが1行以上返します」というエラーが発生しました。limit 2,1
の代わりにlimit 1,2
を使用しました。同様にlimit 3,1
を使用しましたlimit 1,3
関連する問題
- 1. sqlサブクエリは1行以上のエラーを返します
- 2. サブクエリを解決する方法は1行以上返します
- 3. サブクエリは1行以上返します
- 4. サブクエリが1行以上返します
- 5. MySQLエラー:#1242 - サブクエリが1行以上を返します
- 6. 解決方法サブクエリは複数の選択で1行以上のエラーを返します
- 7. サブクエリが1行以上のエラーを返す
- 8. SQLエラー:サブクエリが1つ以上の値を返しました
- 9. mysql:サブクエリが1行以上返す
- 10. サブクエリはselect文で1行以上を返します
- 11. サブクエリは1行以上を返しますか?
- 12. サブクエリはgroup by句で1行以上を返します - MySQL
- 13. サブクエリが2つ以上の値を返しました。エラー
- 14. 1つ以上の値を返すサブクエリを扱う方法
- 15. エラーコード:1242.サブクエリが1行以上を返します - 関数
- 16. MySQLサブクエリエラー:サブクエリが1行以上を返します
- 17. MySQL対処方法:サブクエリは1行以上を返しますか?
- 18. サブクエリが2つ以上の値を返しました。サブクエリ
- 19. ストアドプロシージャエラー:サブクエリが1行以上返します
- 20. Mysql :: Error:サブクエリが1行以上返します。
- 21. SSMSエラー:サブクエリは1つ以上の値を返しましたが、サブクエリはありません
- 22. SQLServerのエラー:サブクエリが1つ以上の値を返しました
- 23. SQLマージアップデートでサブクエリが1つ以上の値を返しましたエラー
- 24. これをMysqlで解決するには(#1242 - サブクエリは1行以上を返します)?
- 25. mysql#1242 - サブクエリが1行以上を返す
- 26. InternalError:(1242 'サブクエリが1行以上を返す')
- 27. サブクエリが1つ以上の値を返しました
- 28. SQL Server - サブクエリが1つ以上の値を返しました
- 29. SQL:サブクエリが1つ以上の値を返しました
- 30. サブクエリが1つ以上の値を返しました
何をしようとしていますか? 同じテーブルの各列に対してSELECTを作成しているようです。 – Borjante
これは次のようなビューを作成するための要件です。 –