Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 静默变量赋值_Mysql_Sql_Client - Fatal编程技术网

Mysql 静默变量赋值

Mysql 静默变量赋值,mysql,sql,client,Mysql,Sql,Client,当从mysql客户机使用mysql时,如何仅静音变量分配 我有一个文件sql.sql: select id := id from companies where name="StackExchange"; select profit, companyID from profits where companyID=@id select easter from egg where easterEgg=@id 如果我运行mysql

当从
mysql客户机
使用
mysql
时,如何仅静音变量分配

我有一个文件
sql.sql

select id := id from companies where name="StackExchange";
select profit, companyID from profits where companyID=@id
select easter from egg where easterEgg=@id
如果我运行
mysql
,我会得到

@id = id
12

profit   companyID
------   ---------
-12000   12

easter
------
egg
expires
April
我想要除变量赋值行以外的所有内容:

profit   companyID
------   ---------
-12000   12

easter
------
egg
expires
April
我希望在编写代码时避免多次重复代码

select profit, companyID from profits where companyID=(select id from companies where name="StackExchange")
select easter from egg where easterEgg=(select id from companies where name="StackExchange")
select something_else from someTable where this_column=(select id from companies where name="StackExchange")

尝试使用临时变量,这不会输出结果,因为它会将其复制到会话变量中

SELECT id INTO @id FROM companies WHERE name="StackExchange";
SELECT profit, companyID FROM profits WHERE companyID=@id;
SELECT easter FROM egg WHERE easterEgg=@id;
试试:
mysql——静默