Mysql选择多个id';

Mysql选择多个id';,mysql,mysql-workbench,Mysql,Mysql Workbench,我需要像这样执行查询: SELECT draw,SUM(uplata) as uplata, SUM(wonamount) as isplata, SUM(uplata)- SUM(wonamount) as stanje, COUNT(*) as ukupno_tiketa FROM macau.tickets WHERE shop ='105' and status != 1 and draw = 1; 我需要执行该查询100次,仅将draw=1更改为draw=2,draw=3,

我需要像这样执行
查询

SELECT draw,SUM(uplata) as uplata, SUM(wonamount) as isplata,
 SUM(uplata)- SUM(wonamount) as stanje,
 COUNT(*) as ukupno_tiketa FROM macau.tickets
 WHERE  shop ='105' and status != 1 and draw = 1; 
我需要执行该查询100次,仅将
draw=1
更改为
draw=2
draw=3
,等等


如何在mysql
workbench
中为每个
select语句获取新行,以便能够将所有内容导出到
csv文件

首先,您需要使用
while循环编写
存储过程

drop procedure if exists load_test_data;
delimiter #
create procedure load_test_data()
begin
declare v_max int unsigned default 100;
declare v_counter int unsigned default 0;
  start transaction;
  truncate table new_table;
  while v_counter < v_max do
    insert into new_table SELECT draw,SUM(uplata) as uplata, SUM(wonamount) 
   as isplata, SUM(uplata)- SUM(wonamount) 
   as stanje, COUNT(*) as ukupno_tiketa 
   FROM macau.tickets WHERE
  shop ='105' and status != 1 and draw = v_counter;
   set v_counter=v_counter+1;
  end while;
  commit;
end #
delimiter ;
您可以将您的
新表格
转储到
csv
文件:

SELECT *
FROM new_table
INTO OUTFILE '[path]/File.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
注意:将[path]替换为您希望文件位于其中的文件夹。请记住,文件夹应该是可写的,并且需要设置所有
完全权限

@BlankName welcome:)但如果这回答了您的问题,请将其标记为已回答,以便关闭。谢谢。
SELECT *
FROM new_table
INTO OUTFILE '[path]/File.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'