DarrenMcGettigan
DarrenMcGettigan

Reputation: 67

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"?

Upvotes: 1

Views: 286

Answers (1)

Uueerdo
Uueerdo

Reputation: 15941

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 

Upvotes: 2

Related Questions