问答详情
源自:-

循环查询问题

我需要连接四张表, 

select o.orderId,u.nickName,o.serveCount,(select u.nickName from user u where u.shortUrl=o.shortUrlServer) nname ,

(select ((count(*) * (total - counterFee))*0.03)) b,-- f交易奖励

(select (count(*) * (total - counterFee))) a,-- 服务费

(SELECT (total - counterFee)) c,e.evaTextContent,e.evaLevle 

from user u 

INNER JOIN orders o on o.shortUrlUser = u.shortUrl 

left JOIN serve s ON o.serveId=s.serveId 

LEFT JOIN evaluate e on e.orderId=o.orderId; 

http://img.mukewang.com/5684e1990001ac4812730314.jpg 现在想取到每一个人(nname)的订单的唯一值,就是统计每一个人的serveCount,这个怎么实现循环查询

提问者:in23 2015-12-31 16:07

个回答

  • sqlercn
    2016-01-08 10:45:10

    最简单的方法,就是把这个查询做为一个子查询,在外面加select nname,count(*) from ( sql ) a group by nname