公告:本站提供编程开发方面的技术交流与分享,打造最佳教程网,希望能为您排忧解难!

mysql数据库中case when 简单例子

mysql数据库中case when 简单例子

更新时间:2013-04-10 20:54:52 |

mysql case when .. then ... else ... end 范例
SELECT max(planid) AS planid,
 max(plan) AS plan,
 max(unitid) AS unitid,
 max(unit) AS unit,
 kwordid,
 (CASE
 WHEN sum(cost)=0
  THEN 0
  ELSE (sum(income)-sum(cost))/sum(cost)
  END
  ) AS roi
FROM `k_kword`
WHERE `vdate`>='2010-12-04'
AND `vdate`<='2011-01-03'
AND `siteid`=103 GROUP BY `kwordid` ORDER BY roi ASC

最佳教程网

最大的技术交流平台 www.goodxyx.com© CopyRight 2011-2013, All Rights Reserved

浙ICP备11033019号