现在做一个图书网站,根据用户买过得最多的书的类别,给他推荐该类的书籍。现在我写了一段查询:
(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)查询出的结果为:
type type_count
20 1
23 6
25 1我现在想取出其中type_count为最大的那一行的type值,遇到了问题。。试了半天也不行, 求大神解决下。
(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)查询出的结果为:
type type_count
20 1
23 6
25 1我现在想取出其中type_count为最大的那一行的type值,遇到了问题。。试了半天也不行, 求大神解决下。
...
Order by count(type) asc
(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
先找出书籍的销量数量,当然top 5左右就可以了,一般推荐5~10本书比较合适。一般这种情况只需要关联1、2个表就可以了。这步不用说吧?要说的话请贴出表结构。然后通过某个用户的id推送。
但是我越想越觉得你这个需求是不是有问题?如果你那句【根据用户买过得最多的书的类别,给他推荐该类的书籍】中的用户是指所有用户?还是里面的“他”?如果是所有用户,那么其实没必要针对某个用户了,直接在所有用户的看书界面展示最多人买的书就可以拉。这样的设计不是更好吗?