案例(选择)时

时间:2018-01-24 06:37:29

标签: sql

正确编译查询。提示如何正确制作。你需要获得三个变量并检查它们。取决于所选的测试日期。

在没有正确写入之后

select sum(t.sum),t3.cost, t.status 
from  Credit t inner join  cost t3 on t.code= t3.code1
where  t.id='1' and 
t.date >= case (SELECT t1.mark1, t1.mark2, t2.mark3
                FROM marks t1 INNER JOIN marksagain t2 ON (t1.id = t2.id)
                WHERE t1.id = t.id)
          when (0,0,6) then (INTNX('month',date(),6,'same')) 
          else(INTNX('month',date(),3,'same')) end
group by t.sum, t3.cost, t.status;`

1 个答案:

答案 0 :(得分:0)

试试这个:

select sum(t.sum),t3.cost, t.status
            from  Credit t inner join  cost t3 on t.code= t3.code1
    where  t.id='1' and t.date >=
        case when (SELECT t1.mark1 FROM marks t1 INNER JOIN marksagain t2 ON (t1.id = t2.id) WHERE t1.id = t.id) = 0
                AND (SELECT t1.mark2 FROM marks t1 INNER JOIN marksagain t2 ON (t1.id = t2.id) WHERE t1.id = t.id) = 0
                AND (SELECT t2.mark3 FROM marks t1 INNER JOIN marksagain t2 ON (t1.id = t2.id) WHERE t1.id = t.id) = 6
        then (INTNX('month',date(),6,'same')) else(INTNX('month',date(),3,'same'))
        end
    group by t.sum, t3.cost, t.status;