我有这个 MySQL 查询:
select Region,
CONCAT('$', FORMAT(AVG(sales), 0)) as 'Average_Sales_by_Region',
count(*) as '# of Dist in state'
from dist, Regions_US
where dist.state=Regions_US.State
group by Region ORDER BY AVG(sales) DESC;
以下是上述 MySQL 查询的输出:
+--------------------+-------------------------------+-------------------------+
| Region | Average_Sales_by_Region | # of Dist in state |
+--------------------+-------------------------------+-------------------------+
| Alaska-Hawaii | $8,150 | 4 |
| Mountain | $20,216 | 74 |
| West North Central | $18,268 | 40 |
| South Atlantic | $16,225 | 178 |
| East South Central | $14,967 | 30 |
| West South Central | $13,704 | 125 |
| East North Central | $12,668 | 79 |
| New England | $11,916 | 32 |
| Pacific | $11,553 | 120 |
| Middle Atlantic | $10,292 | 131 |
+--------------------+-------------------------------+-------------------------+
有一个名为 company_name 的字段,我想对其进行 DISTINCT:
select DISTINCT company_name,
Region,CONCAT('$', FORMAT(AVG(sales), 0)) as 'Average_Sales_by_Region',
count(*) as '# of Dist in state'
from dist, Regions_US
where dist.state=Regions_US.State
group by Region ORDER BY AVG(sales) DESC;
我希望它在“company_name”的字段名称上是 DISTINCT,但我不希望 company_name 字段显示在输出中。有没有办法在不显示 DISTINCT company_name 的情况下执行它?它的语法是什么,它会在上面的 MySQL 查询中使用什么?还是有其他方法可以做到这一点?谢谢!