SELECT product_id, Round(SUM(sales) /SUM(units), 2) AS average_price FROM ( SELECT Prices.product_id AS product_id, Prices.price * UnitsSold.units AS sales, UnitsSold.units AS units FROM Prices JOIN UnitsSold ON Prices.product_id = UnitsSold.product_id WHERE UnitsSold.purchase_date BETWEEN Prices.start_date AND Prices.end_date ) T GROUPBY product_id
SELECT seller_name AS SELLER_NAME FROM Seller WHERE Seller.seller_id NOTIN ( SELECTDISTINCT seller_id AS id FROM Orders WHERE DATE_FORMAT(sale_date, "%Y") =2020 ) ORDERBY SELLER_NAME;
# 窗口 select student_id, course_id, grade from ( select *, dense_rank() over (partitionby student_id orderby grade desc, course_id) rk from enrollments ) t where rk=1
select o.customer_id customer_id, c.customer_name customer_name from orders o JOIN customers c ON o.customer_id = c.customer_id groupby o.customer_id having SUM(IF(o.product_name='A',1,0)) >0 ANDSUM(IF(o.product_name='B',1,0)) >0 ANDSUM(IF(o.product_name='C',1,0))=0
Checking if Disqus is accessible...