我创建了一个查询来获取"prefix_"
的所有表名
SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME LIKE 'prefix_%' AND TABLE_TYPE = 'BASE TABLE'
但是在我的数据库中,我有带prefix_prefix_的表。如何避免选择它们?
您只需将例外添加到where子句即可。
SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME LIKE 'prefix_%' AND TABLE_NAME NOT LIKE 'prefix_prefix_%' AND TABLE_TYPE = 'BASE TABLE'
您可以尝试使用子查询而不是
select * from
(
SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME LIKE 'prefix_%' and AND TABLE_TYPE = 'BASE TABLE'
)A where ABLE_NAME LIKE 'prefix_prefix_%'