我们说我有以下内容:
SELECT
users_aggregate_data.treatment,
SUM(users_aggregate_data.GS_Oct_Dec),
AVG(users_aggregate_data.items_sold_Oct_Dec),
-- .. and a few other such as std_deviation, ..
SUM(users_aggregate_data.GS_Jan_Mar),
AVG(users_aggregate_data.items_sold_Jan_Mar)
-- .. and a few other such as std_deviation, ..
FROM users_aggregate_data
在users_aggregate_date
中,我按客户和时间跨度精心汇总了销售数据。
我想知道是否有办法避免上面的所有样板代码。
答案 0 :(得分:1)
您可以对表名使用别名(这会提高可读性),但您必须指定列名(如果您不想仅使用SELECT *
)
SELECT d.treatment,
SUM(d.GS_Oct_Dec),
AVG(d.items_sold_Oct_Dec),
-- .. and a few other such as std_deviation, ..
SUM(d.GS_Jan_Mar),
AVG(d.items_sold_Jan_Mar)
-- .. and a few other such as std_deviation, ..
FROM users_aggregate_data d
关于别名,您可以在此处阅读更多内容:SQL ALIAS Tutorial