Bug #38651 'View's SELECT contains a variable or parameter', 'unknow field'
Submitted: 8 Aug 2008 2:17 Modified: 8 Aug 2008 5:23
Reporter: Daniel Penza Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: Views Severity:S3 (Non-critical)
Version:5.0.51a OS:Windows
Assigned to: CPU Architecture:Any
Tags: create view

[8 Aug 2008 2:17] Daniel Penza
Description:
Hellow:
When I want to create a view, MySQL reports the following error:
"View's SELECT contains a variable or parameter."
The view caracteristic's are :
The 'Alias' Amount assigned to (Quant * Price) is used in the next field 'Total'
something that:

Create View 'TotalLines' as SELECT Cant * Price as Amount, Amount * (100-Discount)/100 as Total From TableA;
That reports error: "unknow field 'Amount'" 

and that way:

Create View 'TotalLines' as SELECT @Amount:=(Cant * Price), @Amount * (100-Discount)/100 as Total From TableA;

That reports error:"View's SELECT contains a variable or parameter." 

what I do? how fix or do that?

How to repeat:
CREATE TABLE `TableA` (Id INT(4),Price Decimal(10,2),Quant Decimal(10,2),Discount Decimal(10,2));

Create View 'TotalLines' as SELECT Quant * Price as Amount, Amount * (100-Discount)/100 as Total From TableA;

or 

Create View 'TotalLines' as SELECT @Amount:=(Cant * Price), @Amount * (100-Discount)/100 as Total From TableA;

Suggested fix:
it would be extremely usefull,

The 'Alias' Amount assigned to (Quant * Price) may be used in the next field 'Total'

in resume:
I could do some thing like:
Select (A + B) as C, (C + D) as E From TableA
[8 Aug 2008 4:28] Valeriy Kravchuk
Bug #38649 was marked as a duplicate of this one.
[8 Aug 2008 5:23] Sveta Smirnova
Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://dev.mysql.com/doc/ and the instructions on
how to report a bug at http://bugs.mysql.com/how-to-report.php

According to http://dev.mysql.com/doc/refman/5.0/en/create-view.html: " A view definition is subject to the following restrictions: ... The SELECT statement cannot refer to system or user variables. "

According to http://dev.mysql.com/doc/refman/5.0/en/select.html: "A select_expr can be given an alias using AS alias_name. The alias is used as the expression's column name and can be used in GROUP BY, ORDER BY, or HAVING clauses.", but there is no word alias can be used anywhere else.