我有一个销售“表”,并从中创建了一个名为 dailyactivity 的“视图”,它为我提供了每天的总销售额。我正在尝试添加一个累积频率字段,但它返回一个空列。任何人都可以指出我正确的方向。这就是我所拥有的
这就是我想要的
我有一个销售“表”,并从中创建了一个名为 dailyactivity 的“视图”,它为我提供了每天的总销售额。我正在尝试添加一个累积频率字段,但它返回一个空列。任何人都可以指出我正确的方向。这就是我所拥有的
这就是我想要的
询问:
SELECT
d1.Date_TR,
sum(d1.Sales) AS Daily_Sales,
(SELECT SUM(d2.Sales)
FROM dailyactivity d2
WHERE d2.Date_TR <= d1.Date_TR) AS cumulative_sum
FROM dailyactivity d1
GROUP BY d1.Date_TR
ORDER BY d1.Date_TR ASC
此脚本将为任何表创建所需的累积分布函数 (CDF) 查询:
#!/bin/bash
tableName=$1
cdfParam=$2
otherParams=$3
usage(){
echo "Usage: $0 <Table name> <Column/Columns for CDF> [Additional parameters to output]"
echo ""
echo "Get CDF of the Age column from the Persons table and print the Name and Gender of each person"
echo "e.g., $0 Persons Age Name,Gender"
echo ""
echo "Get CDF of the difference between Salary & profil from the Persons table and print the Name and Gender of each person"
echo "e.g., $0 Persons 'Salary-Profit' Name,Gender"
echo ""
echo "Get CDF of Age from a derived table called employeeTable"
echo "e.g., $0 '(select * from Employees) as employeeTable' Age"
exit 1
}
[[ $# -lt 2 ]] && usage
if [ -z "$otherParams" ]
then
echo "SELECT $cdfParam as cdf_paramValue, (SELECT count(*) FROM $tableName WHERE $cdfParam <= cdf_paramValue) AS cumulative_sum FROM $tableName ORDER BY ($cdfParam) desc";
else
echo "SELECT $otherParams,$cdfParam as cdf_paramValue, (SELECT count(*) FROM $tableName WHERE $cdfParam <= cdf_paramValue) AS cumulative_sum FROM $tableName ORDER BY ($cdfParam) desc";
fi