mysql 语句 每月最后一天数据

数据库存的是每天的数据,现在我要的是没月最后一天的数据,不借助php,只用一句mysql搞定
SELECT (
sum( jc_ts_user ) + sum( by_ts_user )
) AS nums, cpname AS info_order, left( ts_date, 7 ) AS ts_Ym
FROM tsrate_tj
WHERE spname = '翔通移动'
AND TYPE = 'MMS'
AND ts_date
IN (
SELECT last_day( ts_date )
FROM tsrate_tj
)
LIMIT 0 , 30
这样写
MySQL 返回:#1064 - You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'select last_day( ts_date ) from tsrate_tj ) LIMIT 0, 30' at li
???怎么解决
mysql版本5.0以下

第1个回答  推荐于2018-03-20
select * from tsrate_tj where date_format(ts_date,'%Y-%m-%d') in (LAST_DAY(STR_TO_DATE('2012-01','%Y-%m-%d')),LAST_DAY(STR_TO_DATE('2012-02','%Y-%m-%d')),LAST_DAY(STR_TO_DATE('2012-03','%Y-%m-%d')),LAST_DAY(STR_TO_DATE('2012-04','%Y-%m-%d')),LAST_DAY(STR_TO_DATE('2012-05','%Y-%m-%d')),LAST_DAY(STR_TO_DATE('2012-06','%Y-%m-%d')),LAST_DAY(STR_TO_DATE('2012-07','%Y-%m-%d')),LAST_DAY(STR_TO_DATE('2012-08','%Y-%m-%d')),LAST_DAY(STR_TO_DATE('2012-09','%Y-%m-%d')),LAST_DAY(STR_TO_DATE('2012-10','%Y-%m-%d')),LAST_DAY(STR_TO_DATE('2012-11,'%Y-%m-%d')),LAST_DAY(STR_TO_DATE('2012-12','%Y-%m-%d')) );
当然了 in 里面的条件可以用程序循环拼出来,年和月 看你具体的业务需求;需要别的条件就 继续 and;至于你要查什么,把*换掉你想要的就OK了;分页的话 直接在后面加 LIMIT。
希望能帮到你,望采纳!本回答被网友采纳
相似回答