我想獲得一個簡單的數據庫查詢工作,但我不能得到clojure/java.jdbc
從IN
子句中進行選擇。如何使用clojure/java.jdbc中的「WHERE x IN y」子句?
的代碼看起來是這樣的:
(sql/with-connection db
(sql/with-query-results rows
["select f.name name
, f.id file_id
from FileCategory fc
join File f
on fc.file = f.id
where fc.category in ?
having count(1) >= ?"
[1 2] ; This is the bit which does not work.
; I have tried (to-array) and (set) too
2]
(into [] rows)))
任何想法如何,我可以通過這組到查詢?
運行查詢直接mysql
下,我沒有得到任何的問題:
mysql> select f.name, f.id from FileCategory fc join File f on fc.file = f.id where fc.category in (1, 2) having count(1) >= 2;
+-----------+----+
| name | id |
+-----------+----+
| some name | 1 |
+-----------+----+
1 row in set (0.02 sec)
mysql>
萬一這讓我使用了一個區別:org.clojure/Clojure的1.4.0,org.clojure/java.jdbc 0.2 .3和mysql/mysql-connector-java 5.1.6。
你不能用準備好的語句來做到這一點。那麼,你可以使用WHERE(?,?)HAVING count(1)> =?'和'1 2 2'作爲數據參數。但不是這樣。 – Esailija 2013-03-22 21:53:49