到目前为止,我有这个:
select created_at,
DATEDIFF(TO_DATE(current_date()), TO_DATE(sales_flat_order.created_at)) as delay,
count(*) over() as NumberOfOrders
FROM
magentodb.sales_flat_order
WHERE
status IN ( 'packed' , 'cod_confirmed' )
GROUP BY TO_DATE(created_at)
但这不起作用。
语法错误:
编译语句时出错:FAILED:SemanticException [错误10004]:第1行:7无效的表别名或列引用'created_at':(可能的列名是:(tok_function to_date(tok_table_or_col created_at)))
< / LI> count(*) does not give sum for each grouped by date but instead all of the rows
。
注意:我实际上使用的是hive,但它与查询
时的sql完全相同答案 0 :(得分:0)
试试这个:
select created_at,
DATEDIFF(TO_DATE(current_date()), TO_DATE(sales_flat_order.created_at)) as delay,
count(*) as NumberOfOrders
FROM
magentodb.sales_flat_order
WHERE
status IN ( 'packed' , 'cod_confirmed' )
GROUP BY Date(created_at)
答案 1 :(得分:0)
我的手机不允许我发表评论。但试试这个链接,它可能会以正确的方式引导你。
stackoverflow.com/questions/29704904/invalid-table-alias-or-column-reference-b
答案 2 :(得分:0)
我认为您希望使用created_at
的日期部分(包括年,月和日)进行分组。
select
date(created_at) as created_at_day,
datediff(curdate(), sales_flat_order.created_at) as delay,
count(*) as numberOfOrders
from magentodb.sales_flat_order
WHERE status IN ('packed', 'cod_confirmed' ) GROUP BY created_at_day
此查询仅显示当天创建的第一个订单。因为你按天分组。您可以使用average
查找当天创建的订单的平均延迟。