我需要针对“按日期售出的特定产品的平均数量。每天售出的至少一种产品”编写SQL查询。
def print_dirs(directories):
try:
dirpath, dirnames, files = next(directories)
print(dirpath) # print current path; no need for join here
for _ in dirnames: # once for each sub-directory...
print_dirs(directories) # ... recursively call generator
for name in files: # now, print files in current directory
print(os.path.join(dirpath, name))
except StopIteration:
pass
print_dirs(os.walk(topdir))
P.S。 PID表示产品ID。
此查询可以吗? 这应该给出正确的答案吗?
答案 0 :(得分:1)
考虑使用distinct
列的date
个计数
SELECT PID,
COUNT(PID)/COUNT(distinct date_) as "Avg.Product Sold By Days"
FROM SOLD
GROUP BY PID;
答案 1 :(得分:0)
您可以在下面尝试此sql查询。基本上,它将为您拥有的每种产品返回平均“销售”数。它将按每个不同的产品ID分组。请向我们提供您的表格等数据结构。
SELECT product_ID, trans_date
Sum(sales_of_product) / COUNT(DISTINCT sold_transaction) AS 'avg'
FROM SOLD
GROUP BY product_ID