create view myview1
as
select a.*,f_statues=case when f_count<=f_finishcount then '1' else '0' end
from t_order a join t_orderitem b on a.f_id=b.f_orderid

解决方案 »

  1.   

    如果是多条的话要循环判断,这样单单靠 select是办不到的我的想法是
    创建一个insert触发器
    循环判断f_count<= f_finishcount 
    把结果更新到视图中创建一个update触发器
    循环判断f_count<= f_finishcount 
    把结果更新到视图中希望听听大家的高见
      

  2.   

    create view myview1
    as
    select a.*, f_statues = case when not exists (
        select 1 from t_orderitem 
        where f_orderid = a.f_id and f_count <= f_finishcount
    ) then 0 else 1 end
    from t_order a 
      

  3.   

    判断条件搞错了,改改
    create view myview1
    as
    select a.*, f_statues = case when not exists (
        select 1 
        from t_orderitem 
        where f_orderid = a.f_id and f_count >= f_finishcount
    ) then 1 else 0 end
    from t_order a
      

  4.   

    zarge(鲨猩) 的语句很漂亮
    向zarge(鲨猩)学习这个方法好
      

  5.   

    create view yy
    as 
    select a.* ,(case when b.f_count-b.f_finishcount>0 then 0 else 1 end ) as f_stutas
    from t_order a, t_orderitem b
    where a.f_id=b.f_orderid
      

  6.   

    zarge(鲨猩)的回复还有点问题,就是当主表有但细表没有的记录它也标记为1
    我觉得是下面这样比较好
    create view v_orderitem
    as
    select t_order.*,status=case when t_order.f_id in
    (select distinct a.f_id    
      from t_order a,t_orderitem c
      where c.f_orderid=a.f_id and not exists
      (select * from t_orderitem b
         where b.f_orderid=a.f_id  and b.f_count>f_finishcount 
         )) then 1 else 0 end
    from T_order   
    在这个视图中,你要注意细表的f_finishcounth和f_count字段不能为空
      

  7.   

    多谢各位帮忙, zarge的语句正合适,只是改f_count >= ...为f_count >就行了, liguanqian2001()的也完全正确,