日期:2014-05-16  浏览次数:20751 次

求一个SQL语句
SELECT UserId,COUNT(1) AS num FROM product GROUP BY userId ORDER BY num desc
这条是在product 表获取每个用户有多少个产品

第二条:select count(1) from subProduct where userId=上面的userId

想要的最终结果是:用户ID 产品总数 SUB的总数


有没有一条SQL语句能解决?

------解决方案--------------------
SELECT UserId,COUNT(1) AS num,
(select count(1) from subProduct where userId=A.userId)

 FROM product A GROUP BY userId ORDER BY num desc