Php 选择distinct并按多个smallint列排序
列Php 选择distinct并按多个smallint列排序,php,mysql,Php,Mysql,列width和height是smallint(6) 我想从width按width asc排序中选择distinct值,然后按height asc排序。 以下是我的尝试: - $sql = "select * from banners group by width order by width, height asc"; - $sql = "select * from banners group by width order by width asc, height asc"; - $sq
width
和height
是smallint(6)
我想从
width
按width asc
排序中选择distinct
值,然后按height asc
排序。
以下是我的尝试:
- $sql = "select * from banners group by width order by width, height asc";
- $sql = "select * from banners group by width order by width asc, height asc";
- $sql = "select * from banners group by width order by width asc, height";
什么都不管用。选择按宽度排列,但按高度排列不正确。使用group by而不是distinct(不允许从mysql 5.7开始)只选择一行,没有明确的名称 对于不在group by中的列名,应在选择和聚合函数中使用显式列名 通过这种方式,您可以真正控制所选值和结果行的顺序 例如: 或
您可以显示一些示例数据吗?以及预期的输出。这可能会帮助您了解为什么
按宽度分组
?@前进,因为我只需要与宽度
不同的值。
select distinct width, height
from banners
order by width, height asc
select width, max(height )
from banners
group by width
order by width, height asc