select name,submittime from enterprise where yearweek(date_format(submittime,'%y-%m-%d')) = yearweek(now());
select name,submittime from enterprise where yearweek(date_format(submittime,'%y-%m-%d')) = yearweek(now())-1;
1)select name,submittime from enterprise where date_format(submittime,'%y-%m')=date_format(now(),'%y-%m')
2)select suggest_id, count(id) as cnt from zhfw_suggest_rank
where read_time >= (date_format(current_date(),'%m')) <= (date_format(current_date(),'%m'))
select name,submittime from enterprise where submittime between date_sub(now(),interval 6 month) and now();
select name,submittime from enterprise where date_format(submittime,'%y-%m')=date_format(date_sub(curdate(), interval 1 month),'%y-%m')
select * from `user` where date_format(pudate,'%y%m') = date_format(curdate(),'%y%m') ;
select * from user where weekofyear(from_unixtime(pudate,'%y-%m-%d')) = weekofyear(now())
select * from user where month(from_unixtime(pudate,'%y-%m-%d')) = month(now())
select * from [user] where year(from_unixtime(pudate,'%y-%m-%d')) = year(now()) and month(from_unixtime(pudate,'%y-%m-%d')) = month(now())
select * from [user] where pudate between 上月最後一天 and 下月第一天
select * from zhfw_service_theme where to_days(created_time) = to_days(now())
select count(*) from `t_view` where datediff(now(),create_time) = 0
select count(*) from `t_view` where datediff(now(),create_time) = 1
select count(*) from `t_view` where datediff(now(),create_time) = 2
多條件查詢比較簡單,即將相應的條件以新增and的形式加在後面,如:
select * from employee
where fnumber between 'dev001' and 'dev008'
and fname like '%j%'
and fsalary between 3000 and 6000
select @rowno := @rowno + 1 as rowno, t.*
from (select t.article_title, t1. name, t.article_createdate
from t_article t
left join t_article_type t1
on t.typeid = t1. name
where t.article_title like '%博士%'
order by article_createdate desc) t,
(select @rowno := 0) t3
order by rowno
select * from tablename limit n,m
//查詢前n行記錄
-- 方法一
select * from table1 limit 0,n;
-- 方法二
select * from table1 limit n;
//查詢後n行記錄
-- 倒序排序,取前n行 id為自增形式
select * from table1 order by id desc dlimit n;
//查詢一條記錄($id)的下一條記錄
select * from table1 where id>$id order by id asc dlimit 1
//查詢一條記錄($id)的上一條記錄
select * from table1 where id<$id order by id desc dlimit 1
記錄一些sql語句
mysql查詢今天 昨天 7天 近30天 本月 上一月 資料 今天 select from 表名 where to days 時間欄位名 to days now 昨天select from 表名 where to days now to days 時間欄位名 1 7天select from 表名 w...
一些常用的 sql語句總結
查詢賣最好的商品名稱 select goods name from indent detail group by goods id order by sum goods num limit 1 查詢張三購買過的商品名稱 select goods name from user join indent ...
MySQL的一些常用SQL語句
備份表 create table 新錶 select from 舊表 建立臨時表 create temporary table tablename id varchar 100 name varchar 100 age varchar 100 刪除臨時表 drop temporary table i...