有大神能帮忙看下这句sql么。。。
现在做一个图书网站,根据用户买过得最多的书的类别,给他推荐该类的书籍。现在我写了一段查询:
(select type,count(type) type_count from(select type from book where id in(select bookid from OrderDetails where orderid in(select id from orders where userid = (select id from userinfo where name='ccccc')))) a group by type ) b)
(select TOP 1 type,count(type) type_count from(select type from book where id in(select bookid from OrderDetails where orderid in(select id from orders where userid = (select id from userinfo where name='ccccc')))) a group by type ) b)ORDER BY COUNT(type) DESC