在空格中使用列名称的Mysql查询

时间:2014-02-26 12:57:35

标签: mysql sql

我有一个包含列机器ID的表,如(311a__)和(311bb__),其中一些像(08576)。如何在SQL中检索它们 - 如何插入机器ID类似的行(311a__)?我的问题如何插入和选择其中包含空格的列。如何检索machine_name =“%s__”的数据是否正确

sql_local = """SELECT id FROM customer_1.pay_machines WHERE machine_name="%s" """ % machine

  retVal = cursor.execute(sql_local)
  if (retVal == 0):
    sql_local = """INSERT INTO customer_1.pay_machines (machine_name, carpark_id) VALUES ("%s", 0)""" % machine

1 个答案:

答案 0 :(得分:2)

使用反引号包围奇数(或reserved word)列名称:

SELECT * 
  FROM  pd 
 WHERE `machine id` = '(%s__)';

编辑:删除了无效的插入查询,因为第一个查询足以作为示例

相关问题