0
我试图在SQLike中构建两级连接,并且无法通过一级连接的阶段。SQLike中的多重连接语法
我作为源表使用JSONs是:
var placesJSON=[{"id":"173","name":"England","type":"SUBCTRY"},{"id":"580","name":"Great Britain","type":"CTRY"},{"id":"821","name":"Southern England","type":"REG"},{"id":"822","name":"Northern England","type":"REG"},{"id":"831","name":"Southwest England","type":"REG"},{"id":"832","name":"Southeast England","type":"REG"},{"id":"833","name":"Western Midlands","type":"REG"},{"id":"834","name":"Eastern Midlands","type":"REG"},{"id":"889","name":"Eastern England","type":"REG"},{"id":"937","name":"Central Southern England","type":"REG"}];
var relationsJSON=[{"son":"173","father":"580"},{"son":"821","father":"173"},{"son":"822","father":"173"},{"son":"831","father":"173"},{"son":"832","father":"173"},{"son":"833","father":"173"},{"son":"834","father":"173"},{"son":"889","father":"173"},{"son":"937","father":"173"}];
的MySQL相当于什么,我试图做的是:
SELECT DISTINCT p.id, p.name, p.type, r.son, r.father, f.name
FROM places p
JOIN places_relations r ON p.id=r.son
JOIN places f ON f.id=r.father
第一级JOIN伟大的作品:
SQLike.q({
SelectDistinct: ['p_id', 'p_name', 'r_son' ,'p_type', 'r_father'],
From: {p:placesJSON},
Join: {r:relationsJSON},
On: function(){return this.p.id==this.r.son}
})
但是当我尝试添加第二个JOIN时,我没有得到任何结果。我使用的语法是这样的:
SQLike.q({
SelectDistinct: ['p_id', 'p_name', 'r_son' ,'p_type', 'r_father', 'f_name'],
From: {p:placesJSON},
Join: {r:relationsJSON},
On: function(){return this.p.id==this.r.son},
Join: {f:placesJSON},
On: function(){return this.f.id==this.r.father}
})
如何得到它的权利任何想法?
谢谢,meze! ( - : – einav 2012-01-30 11:57:43