mysql - mysql Creating a Generated Column
问题描述
I am trying to create a new column in an existing table:
ALTER TABLE `table`.`data`
ADD COLUMN `IndSale` DECIMAL(10,2) GENERATED ALWAYS AS (sum(TotalSale /
Quantity)) VIRTUAL AFTER `InvoiceComment`;
and I am getting the following error:
ERROR 1111: Invalid use of group function
I don't understand what function is considered "group function"?
解决方案
SUM
is a group/aggregate function; it is used in queries such as:
SELECT id, SUM(values) FROM aTable GROUP BY id;
Edit: After Barmar's info below, it dawned on me where to check in the docs...
Without knowing the details of your table, I am guessing something like this would be what you intented:
IndSale` DECIMAL(10,2) GENERATED ALWAYS AS TotalSale/Quantity
推荐阅读
- mysql - 从具有条件的mysql表中获取特定行
- java - JBOSS EAP 7.1 连接到 oracle 12c 数据库
- jena - 在 Pellet (Openllet) 和 Jena 中,如何更改 SWRL 规则?
- javascript - 通过 url 访问滑块中的幻灯片
- winforms - Windows 窗体中的资源
- angular - 如何使用 VS Code 和 tfs 连接到团队项目以进行 Angular 项目
- amazon-athena - Amazon Athena 无法从分区读取数据
- php - 仅在 chrome 上加载时间很慢
- laravel-5 - 使用 laravel 在 hasMany 关系中用外键覆盖主键
- r - 如何从多个每日 TRMM netcdf 文件中排序和创建栅格堆栈