这个mysql内连接代码有什么问题?

时间:2013-06-01 18:19:03

标签: mysql

我创建了这段代码,但似乎没有用。是否适用于where子句paymentnotification.subpayment和collections.status

    $sql = "SELECT collections.categoryid,collections.handler,collections.status,paymentnotification.categoryid,paymentnotification.amount,paymentnotification.payee,paymentnotification.paymentdate 
FROM collections
INNER JOIN paymentnotification
ON paymentnotification.month=collections.month AND paymentnotification.categoryid=collections.categoryid
 WHERE paymentnotification.subpayment=? AND  collections.status=? AND collections.year=? BETWEEN ? AND ?";
$p = $conn->prepare($sql);
$p->execute(array($payment,$status,$year,$monthc,$monthc2));

1 个答案:

答案 0 :(得分:3)

一个问题是:

AND collections.year=? BETWEEN ? AND ?

显然应该是这样的:

AND collections.year=? AND collections.month BETWEEN ? AND ?

(顺便提一下,我建议使用较短的线条,放置良好的换行符。当你必须水平滚动阅读每一行时,很难遵循。)