mysql 如何給sum()添加筛选条件

q1550657045 2016-01-20 03:06:19
$find["state"] = array("in", array(0, 1, 2, 4, 5));
$xyprice = m("xymx")->where($find)->field("sum(price2) as price2")->find();
//计算总的管理奖取现
if ($xyprice && $xyprice["price2"]) {
$xyprice = $xyprice["price2"] * $rsset["tjjzgrate"] * 0.01;
} else {
$xyprice = 0;
}

if ($xyprice + $price > $tgprice) {
$this->error("管理奖总提现不能大于您总投资额的 ".$rsset["tjjzgrate"]."%!");
}
} else {
if ($price < $rsset["tgmxprice1"]) {
$this->error("提现金额必须是" . $rsset["tgmxprice1"] . "元以上");
}

if (0 < ($price % $rsset["hzpricebei"])) {
$this->error("提现金额必须是" . $rsset["hzpricebei"] . "元的整数倍");
}
}



如上代码显示,只是计算price2字段中所有行数的总和,现在想加一个判断条件,判断txtype表当中如果内容为"glj"的才去计算,这样的条件要怎么加呢? 在线等!!!
...全文
972 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
sum(case when txtype = 'glj' then price2 else 0 end)
村里第一帅 2016-01-21
  • 打赏
  • 举报
回复
sum(if(txtype = 'glj', price2, null))

56,677

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧