本文介绍了如何获取表中相同记录的总和/数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我有两张桌子公司和公司喜欢 CompanyLike Id ratingStar 数 Companyid 公司与公司有1对多的关系。一家公司可以有很多喜欢 公司喜欢的桌子看起来像这样 + ---------------------------- + | ID RatingStar Companyid | + ---------------------------- + | 1 5 5636 | | 2 5 5636 | | 3 1 101 | | 4 2 959 | + ---------------------------- + 现在我想得到评级明星的评分,评分明星是多少次5,以及2对每个Companyid的时间多少 我想要这样的结果 + ---------------------------- -------------------------------------------------- ------------- + | ID Companyid评级Star1评级星级2星级等级星级4星级星级5 | + --------------------------------------------- ---------------------------------------------- + | 1 5636 0 0 0 0 2 | | 1 101 0 0 0 0 0 | | 1 959 1 1 0 0 0 | + --------------------------------------------- ---------------------------------------------- + 怎么做? 代码块添加 - OriginalGriff [ / edit] 解决方案 I have two tables Company and CompanyLikeCompanyLikeIdRatingStarCountCompanyidCompany and CompanyLike have 1 to Many relation . One company can have many likesCompany Like Table Will Look Like this+----------------------------+| ID RatingStar Companyid |+----------------------------+| 1 5 5636 || 2 5 5636 || 3 1 101 || 4 2 959 |+----------------------------+Now i want to get count of rating star that how many times RatingStar is 5 , and how many time its 2 against every CompanyidI want my result like this +-------------------------------------------------------------------------------------------+| ID Companyid RatingStar1 RatingStar2 RatingStar3 RatingStar4 RatingStar5 |+-------------------------------------------------------------------------------------------+| 1 5636 0 0 0 0 2 || 1 101 0 0 0 0 0 || 1 959 1 1 0 0 0 |+-------------------------------------------------------------------------------------------+How to do this ?[edit]Code block added - OriginalGriff[/edit] 解决方案 这篇关于如何获取表中相同记录的总和/数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-11 08:45