比如我有一张表A,他有两个字段
id(自增主键)    count(一个整形的数)
我想建一个视图,除了包含表a的两个字段,还有一个字符串字段,当count中的内容大于100,则填入合格,小于100填入不合格。这个语句怎么写,谢谢!

解决方案 »

  1.   

    create view v_test
    as
     select *,case when [count]>100 then '合格' else '不合格' end as type
     from tb
    go
      

  2.   

    create view v_a
    as
    select id,count,case when count >= 100 then '合格' else '不合格' end from A
      

  3.   

    use [yourdatabase]
    go
    -- drop first 
    if object_id('v_test') is not null
    drop view v_test
    go
    -- and then create 
    create view v_test
    as
     select *,case when [count]>100 then '合格' else '不合格' end as type
     from tb
    go
      

  4.   


    CREATE VIEW VIEW1
    AS
    select *,case [count]/100 when 0 then '不合格' else '合格' end from a 
    --我自己已经测验过了 可行