Home >Database >Mysql Tutorial >关于python查询mysql表的问题

关于python查询mysql表的问题

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-06 09:33:08913browse

mysqlpython

1.首先一个表users内包含song_id和Ds字段,其中Ds是时间(datetime)
用python语言,mysqldb模块查询数据users中同时满足一定条件的全部字段输出,

<code>##单条语句正确    sql = "select * from users where Ds='%s' limit 10 " %  dataTime[1]    curs.execute(sql)</code>
<code>##单条语句正确    sql = "select * from users where song_id='%s' limit 10 " %  song_id    curs.execute(sql)</code>

想把这两个查询条件合在一起,应该如何操作?
下面是本人操作不对,返回SQL语法错误。

<code>    sql = "select * from users where Ds=%s and song_id='%s' limit 10 " %  (Ds,song_id)    curs.execute(sql)</code>

新手求大神解决

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn