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——静默
。