mysql查询时,表名部分为变量的查询方法
#mysql查询(表名部分为变量):如 sys_sms_send_his_201907, 其中201907会每月变化;
#注意事项:1.where 前密码留一个空格 2. 条件中的常量不能用单引号,必要用双引号;
set @char_table = concat('sys_sms_send_his_',DATE_FORMAT( CURDATE( ) ,'%Y%m' ));
set @exec_sql = concat('select sms_id,sms_content,bill_id,send_date from ' , @char_table , ' where SMS_CONTENT like "%验证码%" and DATE_FORMAT(send_date,"%Y%m%d") = DATE_FORMAT( CURDATE( ) ,"%Y%m%d" ) ' );
prepare _select from @exec_sql;
execute _select;
deallocate prepare _select;
#注意事项:1.where 前密码留一个空格 2. 条件中的常量不能用单引号,必要用双引号;
set @char_table = concat('sys_sms_send_his_',DATE_FORMAT( CURDATE( ) ,'%Y%m' ));
set @exec_sql = concat('select sms_id,sms_content,bill_id,send_date from ' , @char_table , ' where SMS_CONTENT like "%验证码%" and DATE_FORMAT(send_date,"%Y%m%d") = DATE_FORMAT( CURDATE( ) ,"%Y%m%d" ) ' );
prepare _select from @exec_sql;
execute _select;
deallocate prepare _select;
正文到此结束
- 本文标签: 暂无相关标签
- 本文链接: https://www.jimmy2k.top/article/233
- 版权声明: 本文由JimmyZ的个人博客原创发布,转载请遵循《署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)》许可协议授权