码迷,mamicode.com
首页 > 数据库 > 详细

sql 时间函数用法

时间:2015-12-11 22:21:59      阅读:235      评论:0      收藏:0      [点我收藏+]

标签:

IF(g.give_integral > -1, g.give_integral, c.goods_price)
这个函数的结果要根据g.give_integral的值,如果g.give_integral大于-1函数值就是g.give_integral,否则函数值就是c.goods_price。

SELECT COUNT(r.created_by) AS sa_num,ss.truename,ss.id,
(SELECT COUNT(1) FROM store_sequence_statue WHERE paycar=‘0‘ AND r.customerid=‘3040000100000000002‘ AND STR_TO_DATE(r.created_time,‘%Y-%m-%d‘) BETWEEN ‘2015-09-13‘ AND ‘2015-09-15‘) AS ontime_car,
(SELECT COUNT(1) FROM store_sequence_statue WHERE paycar=‘1‘ AND r.customerid=‘3040000100000000002‘ AND STR_TO_DATE(r.created_time,‘%Y-%m-%d‘) BETWEEN ‘2015-09-13‘ AND ‘2015-09-15‘) AS notime_car,
(IF(COUNT(r.created_by)=0,0,(SELECT COUNT(1) FROM store_sequence_statue WHERE paycar=‘0‘ AND r.customerid=‘3040000100000000002‘ AND STR_TO_DATE(r.created_time,‘%Y-%m-%d‘) BETWEEN ‘2015-09-13‘ AND ‘2015-09-15‘)/COUNT(r.created_by))) AS shulv
FROM store_repair r INNER JOIN sys_admin ss ON ss.id=r.created_by WHERE r.customerid =‘3040000100000000002‘ AND STR_TO_DATE(r.created_time,‘%Y-%m-%d‘) BETWEEN ‘2015-09-13‘ AND ‘2015-09-15‘ GROUP BY r.created_by

 

 

 

sql 时间函数用法

标签:

原文地址:http://www.cnblogs.com/baijin05/p/5040351.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!