每天特定披萨店的平均披萨订单 - SQL

时间:2017-12-21 15:54:25

标签: sql sqlite select average

如何使用SQLite确定特定披萨店的每日平均订单量?

表格如下:

CREATE TABLE pizzaorders (
     id STRING PRIMARY KEY,
     pizza_place STRING,
     created_utc STRING,
);

我设法按比例分配比萨饼店'Dominos'的比萨饼数量(顺便说一句,created_utc属性以UTC世纪格式存储):

SELECT 
   strftime('%d-%m-%Y', created_utc, 'unixepoch') AS dt, 
   COUNT(*) AS orders 
FROM pizzaorders WHERE pizza_place = 'dominos' 
   GROUP BY dt;

26-10-2017|543
24-10-2017|581
18-10-2017|593
30-10-2017|608
31-10-2017|621
25-10-2017|647

但是如何使用AVG()获取特定披萨店每天的平均订单(例如本例中的多米诺骨牌)?

1 个答案:

答案 0 :(得分:1)

您可以将总计数除以不同的天数:

SELECT COUNT(*) /
       COUNT(DISTINCT STRFTIME('%d-%m-%Y', created_utc, 'unixepoch'))
FROM   pizzaorders
WHERE  pizza_place = 'dominos'