PostgreSQL中的内部查询子查询

时间:2018-09-10 09:36:39

标签: sql postgresql

在我的查询中,我需要在派生列上加入子查询:

let date2 = Date().addingTimeInterval(3600)

上面写着select w1.wk_id, (floor(td1.military_hour/4)*4) as military_hour_group , w1.end_date as end_date from work_instances w1 inner join time_table td1 on w1.end_time = td1.time_id inner join ( select (floor(td2.military_hour/4)*4) as td2_military_hour_group, (floor(td3.military_hour/4)*4) as td3_military_hour_group, wk_id from task_instances t1 inner join time_table td2 on t1.end_time = td1.time_id inner join time_table td3 on t1.start_time = td3.time_id ) tq1 on tq1.td2_military_hour_group = military_hour_group and tq1.td3_military_hour_group = military_hour_group and tq1.wk_id = w1.wf_id

我在做什么错? 请帮忙。

2 个答案:

答案 0 :(得分:1)

尝试以下方法:Military_hour_group是您计算出的列,这就是为什么它显示该错误

select w1.wk_id,
(floor(td1.military_hour/4)*4) as military_hour_group ,
w1.end_date as end_date
from work_instances w1
inner join time_table td1 on w1.end_time = td1.time_id
inner join 
(
  select (floor(td2.military_hour/4)*4) as td2_military_hour_group, 
 (floor(td3.military_hour/4)*4) as td3_military_hour_group, wk_id
  from task_instances t1
  inner join time_table td2 on t1.end_time = td1.time_id
  inner join time_table td3 on t1.start_time = td3.time_id  
) tq1
on tq1.td2_military_hour_group = (floor(td1.military_hour/4)*4)
and tq1.td3_military_hour_group = (floor(td1.military_hour/4)*4)
and tq1.wk_id = w1.wf_id 

答案 1 :(得分:0)

好的用法,如下所述

new Countdown(
animation:new StepTween(
 begin: 6,
end: 0,
).animate(_controllerr)
..addStatusListener((AnimationStatus status) {
print(status);
 if (status == AnimationStatus.completed){
_updateQuestion();
 }
  }),
),

void _updateQuestion(){
if(_questionNumber==_newquiz._questions.length-1){
      _scoreUser=finalScore;
      finalScore=0;
      _questionNumber=0;
      _questioRresult=true;
      _controllerr.stop(canceled: false);
      setState((){});
  }else{
    _questionNumber +=1;
    print("geldi ${_questionNumber}");
    _controllerr.forward(from: 0.0);
    setState(() {});
  }
}