我有一个查询,其中返回的某些列是sum()函数的结果,该列的名称为“ sum(price)”,但我希望列名称为“ total”。有没有办法在SQLite中做到这一点?
查询:
SELECT name, sum(price) FROM trades WHERE trader_id = 7 group by symbol;
当前输出:
+------------+-------------+
| name | sum(shares) |
+--------------------------+
| netflix | 523.26|
+--------------------------+
| tesla | 9276.06|
+------------+-------------+
预期输出:
+------------+-------------+
| name | total |
+--------------------------+
| netflix | 523.26|
+--------------------------+
| tesla | 9276.06|
+------------+-------------+
答案 0 :(得分:2)
as total
确实可以满足您的需求。它会创建一个alias。
SELECT name, sum(price) as total FROM trades WHERE trader_id = 7 group by symbol;
答案 1 :(得分:1)
当然,您可以使用列别名:
SELECT name, sum(price) total FROM trades WHERE trader_id = 7 group by symbol;