Linux shell实现MySQL数据库简单查询&&MySQL多表联合查询

来源:互联网 发布:数据列表测试用例 编辑:程序博客网 时间:2024/06/07 06:30

Linux shell实现MySQL数据库简单查询&&MySQL多表联合查询

两张表:

appdb.t_position:

id, appId, appName, eventId, isdel

appdb.t_record:

id, uid, name

根据t_record中的name查找uid,uid对应t_position中的appId,根据uid关联找到相等的appId,关键查询对应的记录的id, appId, appName, eventId, aliasName

# vim test.sh

#!/bin/sh

if [ $# != 1 ]; then
  echo "please use: $0 <name>"
  echo "eg: $0 mytest"
  exit 1
fi

echo $'\n'

name=$1

ccc="select appId, appName, eventId, aliasName from appdb.t_position as a left join appdb.t_record b on a.appId = b.uid where

 a.isdel=0 and b.name=\"$name\""

cmd="\x6D\x79\x73\x71\x6C\x20\x2D\x75\x74\x74\x74\x20\x2D\x70\x31\x32\x33\x34\x35\x36\x37"
cmd2=$(echo -e $cmd)
ret=$($cmd2 -e "$ccc")

if [ -z $ret ]; then
  ret="ERROR: input name not found."

fi

echo $ret$'\n'


原创粉丝点击