如何在节点sequalize.js中的FROM SQL中执行子查询

时间:2017-07-31 15:39:35

标签: javascript node.js postgresql sequelize.js

如何在节点sequalize.js中的FROM SQL中执行子查询 我正在使用节点sequalize.js和postgres SQL。 例如:

SELECT
   name,
   string_agg(date_start::text,' / ') as date_start,
   string_agg(date_end::text,' / ') as date_end,
   string_agg(sem_range::text,' / ') as sem_range

FROM(

SELECT
name,
sem,
date_start,
days,
date_end
[sequelize.literal("CASE WHEN sem = 'S1' THEN date_start - days ELSE NULL END"), 'sem_start'],
[sequelize.literal("CASE WHEN sem = 'S1' THEN date_end - days ELSE NULL END"), 'sem_end'],
[sequelize.literal("CASE WHEN sem = 'S1' THEN to_char(date_start - days,'YYYY/MM/DD') || ' - ' || to_char(date_end - days,'YYYY/MM/DD') ELSE NULL END"), 'sem_range']

FROM semester as semester

GROUP BY sem, date_start, date_end, days) temp

GROUP BY name

1 个答案:

答案 0 :(得分:0)

如果你想进行子查询,那么没有直接的方法,但你可以抛出这个链接。 Is it possible to do a subquery with Sequelize.js? 希望这会有所帮助