[英]Show a MYSQL variable in the result table
How do you show the string value of a user Defined MYSQL variable in the printed table? 如何在打印表中显示用户定义的MYSQL变量的字符串值?
This... 这个...
SELECT CONCAT_WS( ' ', o.FirstName, o.LastName ) AS FirstLast,
`Company`
FROM Orders o
Gives me this.. 给我这个
|---------------|----------|
| FirstLast | Company |
|---------------|----------|
| First1 Last1 | Company1 |
| First2 Last2 | Company2 |
| First3 Last3 | Company3 |
| First4 Last4 | Company4 |
|---------------|----------|
But this... 但是这个...
SELECT @firstlast = CONCAT_WS( ' ', o.FirstName, o.LastName ),
`Company`
FROM Orders o
Gives me this... 给我这个...
|-------------------------------------------------------------|----------|
| @firstlast = CONCAT_WS( ' ', o.FirstName, o.LastName ) | Company |
|-------------------------------------------------------------|----------|
| NULL | Company1 |
| NULL | Company2 |
| NULL | Company3 |
| NULL | Company4 |
|-------------------------------------------------------------|----------|
Obviously this is incorrect, but I don't know what is. 显然这是不正确的,但我不知道这是什么。
How would I 'print' or display the value? 如何“打印”或显示值? I'm not even sure if I made the variable correct! 我什至不确定我是否正确设置了变量!
Any direction or pointers would be great. 任何方向或指针都很好。
The =
operator is for comparison. =
运算符用于比较。 Since @firstlast
is NULL
the result of the comparison is NULL
. 由于@firstlast
为NULL
,因此比较结果为NULL
。
The assignment operator is :=
. 赋值运算符是:=
。
@firstlast := CONCAT_WS(' ', o.FirstName, o.LastName)
Of course, in your specific example there is no advantage in using a variable. 当然,在您的特定示例中,使用变量没有任何优势。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.