Гость
Целевая тема:
Создать новую тему:
Автор:
Форумы / MySQL [игнор отключен] [закрыт для гостей] / динамический insert / 6 сообщений из 6, страница 1 из 1
07.08.2015, 13:05:30
    #39024993
gda
gda
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
динамический insert
всем привет

у меня есть следущий датасет
он содержит данные по опросник - вопросы - ответы по каждому вопросу

Код: sql
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
select tt.id, tt.tag, tt.val from (
select 1  as id, 'quiz_id'     as tag, '20571' as val union all
select 2  as id, 'question_id' as tag, 38091 as val union all
select 3  as id, 'answer_val'  as tag, 10 as val union all
select 4  as id, 'answer_val'  as tag, 11 as val union all
select 5  as id, 'answer_val'  as tag, 12 as val union all
select 6  as id, 'answer_val'  as tag, 13 as val union all
select 7  as id, 'answer_val'  as tag, 14 as val union all
-- 
select 8  as id, 'question_id' as tag, 38092 as val union all
select 9  as id, 'answer_val'  as tag, 15 as val union all
select 10 as id, 'answer_val'  as tag, 16 as val union all
--
select 11 as id, 'question_id' as tag, 38093 as val union all
select 12 as id, 'answer_val'  as tag, 20 as val union all
select 13 as id, 'answer_val'  as tag, 21 as val ) tt



и таблица в которую надо инсертнуть эти данные

Код: plaintext
1.
2.
3.
4.
5.
6.
7.
 [code=sql]
create table quiz_question_answers
(
    quiz_id         bigint,
    question_id     bigint,
    answer          int
)


по сути надо генерить следующие SQL insert:

Код: sql
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
insert into quiz_question_answers(quiz_id, question_id, answer) values (20571, 38091, 10);
insert into quiz_question_answers(quiz_id, question_id, answer) values (20571, 38091, 11);
insert into quiz_question_answers(quiz_id, question_id, answer) values (20571, 38091, 12);
insert into quiz_question_answers(quiz_id, question_id, answer) values (20571, 38091, 13);
insert into quiz_question_answers(quiz_id, question_id, answer) values (20571, 38091, 14);

insert into quiz_question_answers(quiz_id, question_id, answer) values (20571, 38092, 15);
insert into quiz_question_answers(quiz_id, question_id, answer) values (20571, 38092, 16);

insert into quiz_question_answers(quiz_id, question_id, answer) values (20571, 38093, 20);
insert into quiz_question_answers(quiz_id, question_id, answer) values (20571, 38093, 21);



как такое реализовать на MySQL ?
...
Рейтинг: 0 / 0
07.08.2015, 14:13:27
    #39025043
MasterZiv
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
динамический insert
gda,
вставить

insert into quiz_question_answers(quiz_id, question_id, answer)

перед твоим запросом.
...
Рейтинг: 0 / 0
07.08.2015, 14:17:54
    #39025047
gda
gda
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
динамический insert
MasterZiv - это не то что мне надо
...
Рейтинг: 0 / 0
07.08.2015, 14:20:09
    #39025052
MasterZiv
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
динамический insert
gda,

тогда я не знаю, что тебе надо.
...
Рейтинг: 0 / 0
07.08.2015, 14:22:46
    #39025056
gda
gda
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
динамический insert
MasterZiv - почитай задание
...
Рейтинг: 0 / 0
07.08.2015, 16:46:33
    #39025233
gda
gda
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
динамический insert
если кому надо

Код: sql
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
insert into quiz_question_answers(quiz_id, question_id, answer)
select 
(select max(val) from stg_json_structure_my tt
 where tt.id<s.id
   and tag='quiz_id') as quiz_id,
(select max(val) from stg_json_structure_my tt
 where tt.id<s.id
   and tag='question_id') as question_id,
s.val
from stg_json_structure_my s
where tag = 'answer_val'
order by id
...
Рейтинг: 0 / 0
Форумы / MySQL [игнор отключен] [закрыт для гостей] / динамический insert / 6 сообщений из 6, страница 1 из 1
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]