需要在特定行之后插入一行的SQL命令 [英] Need SQL command that will insert a row after specific row
本文介绍了需要在特定行之后插入一行的SQL命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要SQL命令,该命令将在特定行之后插入一行. 示例:-
I need SQL command that will insert a row after specific row. Example:-
在桌子前
Id. Name.
1. Xyz.
2. Xyz
3. Xyz
想要的结果需要在每个具有相同ID的"xyz"之后添加"Abc"数据,例如:-
Want result need to add 'Abc' data after each 'xyz' having same id like:-
Id. Name.
1. Xyz.
1. Abc
2. Xyz
2. Abc
3. Xyz
3. Abc
推荐答案
您需要UNION ALL
:
SELECT t.*
FROM (SELECT id, Name
FROM table t
UNION ALL
SELECT ID, 'Abc'
FROM table t
) t
ORDER BY ID, NAME;
这不会插入行,它只是为您提供运行时视图.如果只想插入,则需要截断表(注意:备份当前表)&执行插入操作.
This will not insert row, it just provide you run time view. If you want only insert then you need to truncate your table (note : take a backup of current table ) & perform insert operation.
这篇关于需要在特定行之后插入一行的SQL命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文