//常用的一些时间函数查询
//昨天
select * from table_name where TO_DAYS(NOW())-TO_DAYS(时间字段名)<=1
//7天
select * from table_name where DATE_SUB(CURDATE(),INTERVAL 7 DAYS)<= date(时间字段名)
//近30天
select * from table_name where DATE_SUB(CURDATE(),INTERVAL 30 DAYS)<= date(时间字段名)
//当月
select * from table_name where DATE_FORMAT(时间字段名,'%Y%m') = DATE_FORMAT(CURDATE(),'%Y%m')
//上一月
select * from table_name where PERIOD_OFF(date_format(now(),'%Y%m'),date_format(时间字段名,'%Y%m'))=1
group by在某些时候可以去重,会将完全相同的数据进行排序,即distinct
SELECT *,SUM(money) as smoney FROM ngo_dog_log WHERE pid=11 GROUP BY smoney DESC
select选择的元素利用(case when **** then ***end )as new_strname
SELECT id,value,pay_value,(case when sales_on='1'
then 100
when sales_on='0'
then 80
end
)as discount,
from yh_products
where type =2 and state =2
order by id desc
//统计【】出现的频次
select substring_index(left(title,INSTR(title,']')-1),']',-1) from 'xxx_table'
select substring_index(substring_index(title,'[',-1),']',-1) from 'xxx_table'