Korma - 加入 sub select 但我如何指定别名?
Korma - join on a sub select but how do I specify an alias?
我想为这个查询中的子选择分配一个别名:
(->
(korma/select* table_a)
(korma/join
(korma/subselect table_b
(korma/fields :id (korma/raw "COUNT(*) AS count"))
(korma/group :id))
(= :id :id)))
这是我要创建的sql:
SELECT * FROM table_a LEFT JOIN (SELECT id, COUNT(*) AS count FROM table_b GROUP BY id) AS b b.id = id;
但目前 sql korma 刚刚生成:
SELECT * FROM table_a LEFT JOIN (SELECT id, COUNT(*) AS count FROM table_b GROUP BY id) id = id;
我需要将子select定义为一个单独的实体,见下文:
(korma/defentity sub-select
(korma/table (korma/subselect table_b
(korma/fields :id(korma/raw "COUNT(*) AS count"))
(korma/group :id)) :b))
(->
(korma/select* table_a)
(korma/join sub-select (= :b.id :id)))
生成以下查询:
SELECT * FROM table_a LEFT JOIN (SELECT id, COUNT(*) AS count FROM table_b GROUP BY id) a.id = id;
我想为这个查询中的子选择分配一个别名:
(->
(korma/select* table_a)
(korma/join
(korma/subselect table_b
(korma/fields :id (korma/raw "COUNT(*) AS count"))
(korma/group :id))
(= :id :id)))
这是我要创建的sql:
SELECT * FROM table_a LEFT JOIN (SELECT id, COUNT(*) AS count FROM table_b GROUP BY id) AS b b.id = id;
但目前 sql korma 刚刚生成:
SELECT * FROM table_a LEFT JOIN (SELECT id, COUNT(*) AS count FROM table_b GROUP BY id) id = id;
我需要将子select定义为一个单独的实体,见下文:
(korma/defentity sub-select
(korma/table (korma/subselect table_b
(korma/fields :id(korma/raw "COUNT(*) AS count"))
(korma/group :id)) :b))
(->
(korma/select* table_a)
(korma/join sub-select (= :b.id :id)))
生成以下查询:
SELECT * FROM table_a LEFT JOIN (SELECT id, COUNT(*) AS count FROM table_b GROUP BY id) a.id = id;