0

我正在尝试使用此 sql 获取每个卖家每年、每月和每天的所有订单总数。我仍在考虑加入,但据我所知,我认为这应该可行

SELECT sellers.username, sellers.registerDate, sellers.sellerid,
orders.orderPrice, orders.orderDate, orders.sellerid,
count(orders.orderPrice) AS products, SUM( orders.orderPrice ) AS total,
FROM  `sellers` 
JOIN
`orders`,
(SELECT SUM( orders.orderPrice ) FROM  `orders` WHERE YEAR( orderDate ) = YEAR( CURDATE( ) ) ) AS year,
(SELECT SUM( orders.orderPrice ) FROM  `orders` WHERE MONTH( orderDate ) = MONTH( CURDATE( ) ) ) AS month,
(SELECT SUM( orders.orderPrice ) FROM  `orders` WHERE orderDate = CURDATE() ) AS day
ON orders.sellerid = sellers.sellerid
GROUP BY sellers.username
HAVING total > 0
ORDER BY total desc
LIMIT 0 , 4

但它给了我一个错误(#1064 - 在第 9 行的“ON orders.sellerid = Sellers.sellerid GROUP BY Sellers.username HAVING”附近)

4

1 回答 1

0
You need to set ON clause on every join table not only the lastone. 

问候

JOIN
    `orders` ON ??? = ???,
    (SELECT SUM( orders.orderPrice ) FROM  `orders` WHERE YEAR( orderDate ) = YEAR(   CURDATE( ) ) ) AS year ON orders.sellerid = sellers.sellerid,
    (SELECT SUM( orders.orderPrice ) FROM  `orders` WHERE MONTH( orderDate ) = MONTH( CURDATE( ) ) ) AS month ON orders.sellerid = sellers.sellerid,
    (SELECT SUM( orders.orderPrice ) FROM  `orders` WHERE orderDate = CURDATE() ) AS day 
         ON orders.sellerid = sellers.sellerid
于 2013-10-19T01:22:44.937 回答