Mysql查询的一些操作(查表名,查字段名,查当月,查一周,查当天)

时间:2022-06-07 12:29:16
查询数据库中所有表名
select table_name from information_schema.tables where table_schema='tools' and table_type='base table';
查询指定数据库中指定表的所有字段名column_name

select column_name from information_schema.columns where table_schema='tools' and table_name='content_noteinfo'

select * from wap_content where week(created_at) = week(now)
如果你要严格要求是某一年的,那可以这样
查询一天:
select * from table where to_days(column_time) = to_days(now());
select * from table where date(column_time) = curdate();
查询一周:
select * from table  where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(column_time);
查询一个月:
select * from table  where DATE_SUB(CURDATE(), INTERVAL INTERVAL 1 MONTH) <= date(column_time);