我正在尝试在clojure中解决查询。它必须只返回一行。但它正在返回多行。该函数从Customer表中选择正确的行,但随之而来的是从队列表中获取所有3行以及从服务表中获取所有4行。所以我完全得到12(1X3X4)行而不是只有一行。任何建议都会有所帮助。感谢。
SELECT a.first_name, b.queue_name, c.service_name
from customer a
JOIN queue b
on a.queue_id = b.queue_id
JOIN service c
on a.service_id = c.service_id
where a.empl_id = 'BA123';
(defn query-using-map
"Generates a query using a honey sql map and returns the results"
[query-map]
(jdbc/with-db-transaction [conn {:datasource config/datasource}]
(let [sql-query (sql/format query-map)
query-result (jdbc/query conn sql-query)]
query-result)))
(defn get-servicename-queuename [emplid]
(jdbc/with-db-transaction [conn {:datasource config/datasource}]
(let [result (query-using-map
{:select [:a.first_name :b.queue_name :c.service_name]
:from [[:customer :a] [:queue :b] [:service :c]]
:join [":a.queue_id=:b.queue_id and :a.service_id=:c.service_id"]
; OR :join [[:= :a.queue_id :b.queue_id] [:= :a.service_id :c.service_id]]
:where [:= :a.empl_id emplid]})](println result))))
;(get-servicename-queuename "BA123")