javascript - 将 SQL 行拆分为两行并正确构建

标签 javascript python sql c

我有大量查询,例如:

INSERT INTO `test` (`test_id`, `test_title`, `test_pic`, `test_date`, `test_date`, value) VALUES 
(10, 'Dance0', 'NoPhoto.jpg', '1900-01-01 00:00:00', 0), 
(11, 'Dance1', 'NoPhoto.jpg', '1900-01-01 00:00:00', 0), 
(12, 'Dance2', 'NoPhoto.jpg', '1900-01-01 00:00:00', 0), 
(13, 'Dance3', 'NoPhoto.jpg', '1900-01-01 00:00:00', 0)

我想拆分并添加 id,并关闭查询的括号 (),):

(10, 'Dance0', 'NoPhoto.jpg'),
(10, '1900-01-01 00:00:00', 0),
(11, 'Dance1', 'NoPhoto.jpg'),
(11, '1900-01-01 00:00:00', 0), 
(12, 'Dance2', 'NoPhoto.jpg'),
(12, '1900-01-01 00:00:00', 0), 
(13, 'Dance', 'NoPhoto.jpg'),
(13, '1900-01-01 00:00:00', 0), 

这怎么能做到呢?问题的示例/解决方案将非常感激

谢谢

最佳答案

最简单的方法是在加载数据后重组数据。为此:

select test_id, test_title, test_pic
from test
union all
select test_id, test_date, value
from test;

我非常不清楚为什么你想要这样做。原始数据的格式似乎正确。

编辑:

如果你想创建两个表:

create table table1 as
    select test_id, test_title, test_pic
    from test;

create table table2 as
    select test_id, test_date, value
    from test;

关于javascript - 将 SQL 行拆分为两行并正确构建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55660664/

相关文章:

python - SQLAlchemy:相关子查询中仍然存在 FROM 条目

python - 未绑定(bind)本地错误: local variable 'fullfilename' referenced before assignment

java - Postgres : syntax error at or near "as"

mysql - 解析 MySQL 中的自定义日期格式

javascript - 如何从谷歌条形图中删除右侧文本?

javascript - Ember.TextField 值绑定(bind)到父 View

python - 鸡蛋和零件之间的构建有什么区别?

sql - Postgresql 替换函数

javascript - 制作一个不断扩大的圈子,揭示内容背后的规模

javascript - 内联 JavaScript 表单验证