gpt4 book ai didi

mysql - Bash 脚本 : Mysql query field to variable

转载 作者:行者123 更新时间:2023-11-29 14:03:34 25 4
gpt4 key购买 nike

我正在尝试获取记录集并从中读取一些字段。我无法弄清楚如何将字段放入变量中。脚本是:

#!/bin/bash
sqlQuery="$(mysql -h host -u user -ppass -D oberonsaas_v2 -s -N -e
'select ventas.id_venta,
ventas_entradas.id_ventas_entradas,
ventas.id_evento,
id_tarifa,
DATE_FORMAT(fecha_evento,"%Y%m%d") as fecha,
TIME_FORMAT(pase,"%H%i") as pase

from pases,ventas,ventas_entradas,recintos

where ventas.id_recinto = recintos.id_recinto
and ventas.id_pase = pases.id_pase
and ventas.id_venta = ventas_entradas.id_venta
and recintos.id_cliente = 32
and ventas.estado="Pagada"
and date(fecha_venta) = date_add(date(CURRENT_TIMESTAMP),INTERVAL -1 day)')"
echo $sqlQuery

我获取了 $sqlQuery 中的所有记录集,但我想执行循环并连接字段。

最佳答案

好吧,我发明了一些输出

#!/bin/bash

Result="21,336,purchase,tarif_exspensive,Jose"
(IFS=","
for i in $Result
do
echo "I Have: " $i
done
)

输出为

$ bash t5.sh 
I Have: 21
I Have: 336
I Have: purchase
I Have: tarif_exspensive
I Have: Jose

关于mysql - Bash 脚本 : Mysql query field to variable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14711229/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com