Home > Database > Mysql Tutorial > MYSQL很好的SQL语句_MySQL

MYSQL很好的SQL语句_MySQL

WBOY
Release: 2016-06-01 13:29:03
Original
1147 people have browsed it

bitsCN.com

MYSQL很好的SQL语句

 

MYSQL-

1.将查询结果中的0/1分别显示女/男SELECT CASE sexWHEN 1 THEN '男'WHEN 0 THEN '女'ELSE '不确定'ENDFROM carsystem.user2.删除表的一列alter table TEST_USER drop column age3.只更新当天登陆的民警的退出时间Update policemenlogin set quitdate=now() WHERE policemenId='p4' and to_days(logindate)8to_days(now())4.查过去24小时之内的数据(一下内容参见另一篇文章:2013.10.13 事务特性、MYSQL 触发器、存储过程、函数)核心:checkDate >DATE_ADD(now(), INTERVAL -1 DAY)String sql = "select * from records where vehicleId='" + vehicleId+ "' and checkDate >DATE_ADD(now(), INTERVAL -1 DAY)"+ " order by checkDate DESC";DATE_ADD(now(),INTERVAL -1 DAY);系统函数,指当前时间减去1天,即过去24小时时间段内5.按天数统计数据数量SELECT COUNT(*),records.checkdate FROM records GROUP BY TO_DAYS(records.checkdate);6.按月份统计数据数量SELECT COUNT(*),records.checkdate FROM records GROUP BY MONTH(records.checkdate);7.获取当天数据select * from policemenlogin where DATE_FORMAT(logindate,'%Y-%m-%d')=CURDATE();//取当天数据8.按月份分组SELECT  DATE_FORMAT(time,'%Y%m') t,COUNT(*) '数量' FROM `user` GROUP BY PERIOD_DIFF( t,'200001');PERIOD_DIFF( t,'200001');//返回2000年01月到t时间的总月份数
Copy after login

 


bitsCN.com
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template