我想创建一个相当大的基础的小备份(这样开发人员可以下载 ~1-2gb 而不是 15gb)。
为了做到这一点,我复制了基础并运行了一些截断某些表(日志等)的脚本,并且我想删除除某些用户(总是相同的用户)之外的数据。
现在我有这个:
-- delete order details not in test accounts
DELETE FROM order_details WHERE Album_ID NOT IN (
SELECT Album_ID FROM albums WHERE User_ID IN (
SELECT User_ID FROM users
WHERE Email_ID LIKE '%@xxx.com'
OR Email_ID LIKE '%@yyy.com'
OR Email_ID LIKE '%@zzz.com'
)
)
DELETE FROM orders WHERE User_ID NOT IN (
SELECT User_ID FROM users
WHERE Email_ID LIKE '%@xxx.com'
OR Email_ID LIKE '%@yyy.com'
OR Email_ID LIKE '%@zzz.com'
)
-- delete albums not in test accounts
DELETE FROM albums WHERE User_ID NOT IN (
SELECT User_ID FROM users
WHERE Email_ID LIKE '%@xxx.com'
OR Email_ID LIKE '%@yyy.com'
OR Email_ID LIKE '%@zzz.com'
)
-- snip a few more of the same
如您所见,我总是SELECT User_ID FROM users WHERE Email_ID LIKE '%@xxx.com' OR Email_ID LIKE '%@yyy.com' OR...
在很多地方使用相同的子查询。
你将如何做到这一点,这样你就不必重复自己?
谢谢 !