显示多个值MySQL

南非

我是MySQL的新手,需要一些作业方面的帮助,我已经在www.w3schools.com上进行了研究,并测试了许多查询,但找不到正确的方法。

问题是“将交付多件礼物送给几所房子?” 从这个数据库中,我算出有6个地址的孩子收到的礼物多于1个,但根据我的查询,我无法弄清楚仅显示这6个房屋中有2个或3个礼物的情况。

我的查询是:

SELECT address, SUM(goodBehaviour) AS `Households with multiple presents delivered` 
FROM wishlist
WHERE goodBehaviour >0
GROUP BY address;

我的数据库和输出已附加:

MySQL数据库:

查询输出:

我在这里想念什么?

凯里

实际上,您的代码选择的地址> 0,但是如果不是导致问题的原因,则....

When you say 2 or 3 I assume you mean > 1 also the question title indicates that you want to know how many meet the criteria - I am not being pedantic but just want to give the correct answer :-) The code below should display the addresses that match your selection. If you just want totals you can include the count function. Also attaching files as jpegs is helpful but actual data or sql is better because people can cut and paste to replicate your problem and test instead of having to read it and type it in. Hope this helps.

SELECT *, SUM(goodBehaviour) AS SUM FROM wishlist
 GROUP BY address
having SUM(goodBehaviour) >1

Attach an sql table dump and I will check and provide code for your actual problem

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章