MySQL Need返回计数的cols的唯一组合 [英] MySQL Need return a count of unique combinations of cols

查看:81
本文介绍了MySQL Need返回计数的cols的唯一组合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个视频游戏,并使用MySQL来显示一个图标,该图标向玩家显示宝藏所在的位置.数据库将它们的位置X和Y存储在正方形地图上.我还要计算每个方格上的项目数.

I'm coding a video game and using MySQL to display an icon showing the player where treasure is located. The database stores the locations by their X and Y on a square map. I would like to also count the number of items on each square.

给定这样的表格

Id   x   y
==  ==  ==
1    2   3
2    3   2
3    3   2
4    4   4
5    4   4
6    4   4

我想让事情恢复

x y count
= = =====
4 4 3
3 2 2
2 3 1

推荐答案

对结果使用GROUP BY子句.

Select x, y, count(*) as 'count' from mytable group by x, y

这篇关于MySQL Need返回计数的cols的唯一组合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆