我使用Cube.js从Postgres获取数据。默认情况下,cube.js对两个选定的表进行左连接。有什么办法可以通过完全外接获得结果吗?
用户登记表
ID时间
1 10:00
3 9.00
最后活动表
ID时间
1 11:00
2 10:00
所以我想要的输出是
ID Last_active_time Register_time
11:00 10:00
2 10:00
3-9点
发布于 2019-10-30 21:35:46
Cube.js只使用LEFT JOIN
来表示多维数据集之间的关系,以鼓励正确的Cube.js模式设计:https://cube.dev/docs/joins。您的情况可以表示为以下Cube.js模式:
cube(`Users`, {
sql: `
SELECT DISTINCT id FROM users_register
UNION
SELECT DISTINCT id FROM last_active`,
joins: {
UsersRegister: {
sql: `${Users}.id = ${UsersRegister}.id`,
relationship: `hasMany`
},
UsersLastActive: {
sql: `${Users}.id = ${UsersLastActive}.id`,
relationship: `hasMany`
}
},
dimensions: {
id: {
sql: `id`,
type: `number`,
primaryKey: true
}
}
});
cube(`UsersRegister`, {
sql: `select * from users_register`,
measures: {
registerTime: {
sql: `time`,
type: `min`
}
},
dimensions: {
id: {
sql: `id`, // if id is unique within users_register
type: `number`,
primaryKey: true
}
}
});
cube(`UsersLastActive`, {
sql: `select * from last_active`,
measures: {
lastActiveTime: {
sql: `time`,
type: `max`
}
},
dimensions: {
id: {
sql: `id`, // if id is unique within last_active
type: `number`,
primaryKey: true
}
}
});
查询以获得所需的结果:
{
measures: ['UsersLastActive.lastActiveTime', 'UsersRegister.registerTime'],
dimensions: ['Users.id']
}
https://stackoverflow.com/questions/58632821
复制相似问题