Flutter-UI-Button集合

mysql的事务四个特性以及事务的四个隔离级别

  返回  

1251 平均售价

2021/8/21 21:44:51 浏览:

题目描述:
在这里插入图片描述
编写SQL查询以查找每种产品的平均售价。
average_price 应该四舍五入到小数点后两位。
查询结果格式如下例所示:
在这里插入图片描述
方法1:
主要思路:解题链接汇总

# Write your MySQL query statement below
SELECT
    product_id,
    Round(SUM(sales) / SUM(units), 2) AS average_price
FROM (
    SELECT
        p.product_id AS product_id,
        p.price * u.units AS sales,
        u.units AS units
    FROM Prices as p
    JOIN UnitsSold as u 
    ON p.product_id = u.product_id
    WHERE u.purchase_date >= p.start_date AND u.purchase_date <= p.end_date
) T
GROUP BY product_id
# Write your MySQL query statement below
select distinct p.product_id,round(sum(p.price*u.units)/sum(u.units),2) as 'average_price'
from Prices as p left join UnitsSold as u on p.product_id=u.product_id
where u.purchase_date between p.start_date and p.end_date
group by p.product_id

联系我们

如果您对我们的服务有兴趣,请及时和我们联系!

服务热线:18288888888
座机:18288888888
传真:
邮箱:888888@qq.com
地址:郑州市文化路红专路93号