用sql语句实现统计所有供应商供应量的最大、最小和平均值,保存到一张新表中
时间: 2024-03-09 15:48:13 浏览: 25
好的,以下是 SQL 语句实现统计所有供应商供应量的最大、最小和平均值并保存到一张新表中:
```sql
-- 创建新表
CREATE TABLE supplier_stats (
supplier_id INT PRIMARY KEY,
max_quantity INT,
min_quantity INT,
avg_quantity DECIMAL(10,2)
);
-- 统计并插入数据
INSERT INTO supplier_stats (supplier_id, max_quantity, min_quantity, avg_quantity)
SELECT supplier_id, MAX(quantity), MIN(quantity), AVG(quantity)
FROM supply_table
GROUP BY supplier_id;
```
以上 SQL 语句会根据 `supply_table` 表中的供应量数据,按照供应商分组并统计最大、最小和平均值,然后将结果插入到新建的 `supplier_stats` 表中,以供后续查询使用。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![application/msword](https://img-home.csdnimg.cn/images/20210720083327.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)