下面的查询给我一个错误:是否可以在MySQL中做这样的子查询?
select
case
when exists (select username from table_name)
then concat('_username_', table_name)
else table_name
end
from information_schema.tables
where table_schema = 'test'
我基本上要返回_username_(the table name)
如果表中包含一个名为“用户名”栏。
我知道还有另一种方法可以通过选择information_schema.columns
来做到这一点,但我已经像上面那样做了(如果可能的话)。
编辑:我想我的查询获取数据库测试中的所有表。如果表有列用户名,那么我希望它返回_username_(followed by table name)
,否则返回表名
更改您希望能够从查询中完成的问题。 – Layke
@Strawberry为什么复制?这里提出的问题与您提供的链接中提出的问题不同。 –