1
MySQLクエリのみを使用すると、JSONオブジェクトのリストを単一の列に変換して選択する方法がありますか?例えばjsonオブジェクトの配列を選択
私は各event
ため(S)event_time
多くがあり、本質的にテーブルevent
に子テーブルevent_time
を有します。私は何をしようとしていることは、次のようなクエリを作成します:
select e.*, (some select and conversion to a json array query) as 'event_times'
from event e;
私は、MySQLのJSON_OBJECT
とJSON_ARRAY
を結合しようとしてきたが、それをサポートしていないようです。
次のクエリは動作しますが、返す
select e.*,
(select json_object("id", et.id, "event_id", et.event_id, "start_time", et.start_time, "end_time", et.end_time)
from event_time et
where et.event_id = e.id
LIMIT 1) as 'event_times'
from event e;
(理由LIMIT 1
の)私に望ましい結果を与えるものではありません。誰かへの道がある場合
はからの結果を詰め込みますこのクエリ
select json_object("id", id, "event_id", event_id, "start_time", start_time, "end_time", end_time) as 'event_time' from event_time;
JSON_ARRAY
私はそれが与えると感じます私が探しているもの。どんな助けでも大歓迎です。
私はhttp://stackoverflow.com/questions/37470949/how-do-i-generate-nested-json-objects-using-mysql-native-json-先日これに類似した質問に答えました関数/ 37474200#37474200 –
私が必要としてくれたおかげで@BradBaskin。 – Tyler