mySQl - 如何将 MAX() 函数与其他查询属性一起使用
mySQl - How to use MAX() function with other query attributes
下午好:
给定某个数据库,我正在尝试以下 SQL 查询:
select id, date, shop, max(sold_units) from storage where id='9911110810110319890031009710810111097';
上面的 SQL 编译得很好,但我遇到了以下情况:列 max(sold_units) 显示最大值(正确),但是,其他属性(id、date , shop) 引用了另一行,这是不正确的(因为另一个箭头没有 sold_units 的最大值)。如何修改上面的查询,使属性“id”、“date”、“shop”与 max(sold_units).
在同一行中
换句话说,它应该显示销售量最大的行中的 id、日期、商店和 max(sold_units)。
感谢您的关注
您的查询格式不正确。它应该生成语法错误,因为 select
有 max()
所以这是一个聚合查询。但是没有group by
。 select
也有未聚合的列。
我怀疑你打算:
select id, date, shop, sold_units
from storage s
where id = '9911110810110310511110897109971031009710810111097'
order by sold_units desc
limit 1;
下午好: 给定某个数据库,我正在尝试以下 SQL 查询:
select id, date, shop, max(sold_units) from storage where id='9911110810110319890031009710810111097';
上面的 SQL 编译得很好,但我遇到了以下情况:列 max(sold_units) 显示最大值(正确),但是,其他属性(id、date , shop) 引用了另一行,这是不正确的(因为另一个箭头没有 sold_units 的最大值)。如何修改上面的查询,使属性“id”、“date”、“shop”与 max(sold_units).
在同一行中换句话说,它应该显示销售量最大的行中的 id、日期、商店和 max(sold_units)。
感谢您的关注
您的查询格式不正确。它应该生成语法错误,因为 select
有 max()
所以这是一个聚合查询。但是没有group by
。 select
也有未聚合的列。
我怀疑你打算:
select id, date, shop, sold_units
from storage s
where id = '9911110810110310511110897109971031009710810111097'
order by sold_units desc
limit 1;