在python中导入sql语句总是报错

huagefeng 2023-03-07 11:09:20
在python中导入sql语句总是报错,最近新上手,有没有大佬帮忙分析一下


queries={
   'Inter_in_flow': 'SELECT  h.name hname,it.NAME itname,round(avg(tru.value_avg)/1000/1000,5) vel FROM items it,trends_uint  tru,hosts h WHERE it.itemid = tru.itemid  AND h.name in (select name from hosts where  (name like '%%%%-Spoke-%%%%' OR name like '%%%%-Hub-%%%%') status=0 AND h.hostid = it.hostid  AND it.NAME REGEXP '【Internet】'  AND it.NAME REGEXP '【Inbound Flow】Monitor$' AND tru.clock < unix_timestamp('2023-01-01') and  tru.clock > unix_timestamp('2022-12-01')  group by itname,hname order by hname;'
   'Inter_out_flow':'SELECT  h.name hname,it.NAME itname,round(avg(tru.value_avg)/1000/1000,5) vel FROM items it,trends_uint  tru,hosts h WHERE it.itemid = tru.itemid  AND h.name in (select name from hosts where (name like '%%%%-Spoke-%%%%' OR name like '%%%%-Hub-%%%%') and status=0) AND h.hostid = it.hostid  AND it.NAME REGEXP '【Internet】'  AND it.NAME REGEXP '【Outbound Flow】Monitor$' AND tru.clock < unix_timestamp('2023-01-01') and  tru.clock > unix_timestamp('2022-12-01')  group by itname,hname order by hname;'
}

 

 

...全文
7084 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_37413345 2023-04-15
  • 打赏
  • 举报
回复

在这个查询语句中,您使用了单引号'将字符串括起来,并且在字符串中使用了百分号%来进行模糊匹配,但是您还在字符串中使用了单引号,这可能导致查询语句的语法出现问题。

解决此问题的方法是将字符串括起来的方式从单引号'改为双引号",并使用转义字符"来转义字符串中的双引号。此外,在字符串中使用百分号%时,应该将其转义为两个百分号%%,以便正确地进行模糊匹配。

下面是修改后的查询语句:

queries={
   "Inter_in_flow": "SELECT  h.name hname,it.NAME itname,round(avg(tru.value_avg)/1000/1000,5) vel FROM items it,trends_uint  tru,hosts h WHERE it.itemid = tru.itemid  AND h.name in (select name from hosts where  (name like '%%%%-Spoke-%%%%' OR name like '%%%%-Hub-%%%%') status=0 AND h.hostid = it.hostid  AND it.NAME REGEXP '【Internet】'  AND it.NAME REGEXP '【Inbound Flow】Monitor$' AND tru.clock < unix_timestamp('2023-01-01') and  tru.clock > unix_timestamp('2022-12-01'))  group by itname,hname order by hname;",
   "Inter_out_flow":"SELECT  h.name hname,it.NAME itname,round(avg(tru.value_avg)/1000/1000,5) vel FROM items it,trends_uint  tru,hosts h WHERE it.itemid = tru.itemid  AND h.name in (select name from hosts where (name like '%%%%-Spoke-%%%%' OR name like '%%%%-Hub-%%%%') and status=0) AND h.hostid = it.hostid  AND it.NAME REGEXP '【Internet】'  AND it.NAME REGEXP '【Outbound Flow】Monitor$' AND tru.clock < unix_timestamp('2023-01-01') and  tru.clock > unix_timestamp('2022-12-01')  group by itname,hname order by hname;"
}

在这个修改后的查询语句中,字符串使用双引号括起来,并且在字符串中的百分号使用了两个百分号%%来进行模糊匹配。

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧