使用的是mysql
有这么系列表
a_1004
a_1005
a_1006
...
1004是10年4月这个月是4月,怎么写一条sql语句查询a_1004表中的,等到5月,可以查询a_1005表select concat("a_",(select substring(DATE_FORMAT(Date_add(now(), interval 0 day),'%Y%m'),3,4)));得到的是 a_1004怎么样可以查询 这个字符串为表名的表?谢谢,by phoenix
有这么系列表
a_1004
a_1005
a_1006
...
1004是10年4月这个月是4月,怎么写一条sql语句查询a_1004表中的,等到5月,可以查询a_1005表select concat("a_",(select substring(DATE_FORMAT(Date_add(now(), interval 0 day),'%Y%m'),3,4)));得到的是 a_1004怎么样可以查询 这个字符串为表名的表?谢谢,by phoenix
解决方案 »
- VC 调用mysqldump的备份问题
- access denied for user ''@'localhost'(using password:NO)
- 把类似16进制的字符转汉字,用select char()和unhex(),得到的是乱码
- mysql in语句的排序探讨
- asp+mysql中set names语句?
- postgreSQL中文问题
- 请问mysql里如何模糊查找中文字段???
- insert into ta select xx 如何产生不一样的ID?
- 【紧急求助】linux服务器MYSQL无规律的自动终止,导致网站无法运行
- mysql5.7.11安装出现错误,请看抓屏和log文件。
- 一道题:SNS中群组数据库的保存方式
- mysql 不支持子查询 。那应该如何实现查询啊。
prepare qq from @aa;
execute qq;
PREPARE stmt FROM @sql;
EXECUTE stmt1 ;
DEALLOCATE PREPARE stmt1;
select 1004 as m, * from a_1004
union all
select 1005 as m, * from a_1005
union all
select 1006 as m, * from a_1006
) where m=DATE_FORMAT(now(),'%y%m');或者效率高一些的select * from (
select * from a_1004 where DATE_FORMAT(now(),'%y%m')=1004
union all
select * from a_1005 where DATE_FORMAT(now(),'%y%m')=1005
union all
select * from a_1006 where DATE_FORMAT(now(),'%y%m')=1006
)