SELECT *,
SUM(price+shipping+paypalfee+storefee) AS totalcost,
customerpaid AS totalrevenue,
(totalcost - totalrevenue) AS profit
FROM tblsales
GROUP BY orderno
HAVING " . $having . "
ORDER BY $sort $order
LIMIT $offset,$rows
如果我省略
(totalcost - totalrevenue) as profit
,查询就能正常运行。如何在同一查询中使用totalcost和totalrevenue计算PROFIT呢?
group by
的作用吗?在select
中有列不在group by
列表中通常是没有意义的。也许扩展文档可以帮到你:http://dev.mysql.com/doc/refman/5.6/en/group-by-handling.html。 - Gordon Linoff