我正在尝试使用 Pypika(https://pypika.readthedocs.io/en/latest/3_advanced.html)构建一个简单的 SQL 选择查询,我需要为导入的数据列提供别名。我希望看到生成的查询如下。
SELECT "date" AS "x_date","count" AS "x_count" FROM "trades_features" WHERE "ticker"='AAU' AND "date" BETWEEN '2012-12-26' AND '2016-12-29';
我尝试过的Pypika语法如下
from pypika import Query,Table
tb = Table('trades_features')
query = Query.from_(tb).select(tb.date.as_('x_date'), tb.count.as_('x_count')).where(tb.ticker == 'AAU').where(tb.date['2012-12-26':''2016-12-29'])
print(query.get_sql())
产生,
SELECT "date" "x_date","count" "x_count" FROM "trades_features" WHERE "ticker"='AAU' AND "date" BETWEEN '2015-01-01' AND '2016-01-01'
为什么AS
缺少原因?我在这里想念什么?