使用multiselect时SQL语法出错

时间:2014-05-08 08:41:25

标签: mysql sql pymysql

美好的一天!

我的mysql语法有些问题。我只需要选择最多SID个,输入值' count' 我尝试用pymysql做这样的事情:

SELECT `name` FROM `files` WHERE


SELECT `sid` FROM `origin_files` WHERE `name` LIKE %s
ORDER BY `sid` DESC LIMIT 1 >= %s",(name, count);

Mysql表示语法中存在错误。

desc文件:

+-------+--------------+------+-----+---------+-------+
| Field | Type         | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+-------+
| name  | varchar(50)  | NO   |     | NULL    |       |
| sid   | int(4)       | NO   |     | NULL    |       |
| path  | varchar(200) | NO   | PRI | NULL    |       |
+-------+--------------+------+-----+---------+-------+

desc origin_files:

+-------+--------------+------+-----+---------+-------+
| Field | Type         | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+-------+
| name  | varchar(50)  | NO   |     | NULL    |       |
| sid   | int(4)       | NO   |     | NULL    |       |
| path  | varchar(200) | NO   | PRI | NULL    |       |
+-------+--------------+------+-----+---------+-------+

如果你能帮助解决这个问题,我将不胜感激。

1 个答案:

答案 0 :(得分:1)

SELECT field
FROM TABLE_NAME
WHERE field IN
    (SELECT field
     FROM TABLE_NAME
     WHERE field LIKE '%s'
     ORDER BY field DESC);