CREATE VIEW tgtj(县市,数量) 
AS 
 SELECT 
    杭州=sum(case SourceFrom when '杭州' then 1 else 0 end),
    武汉=sum(case SourceFrom when '武汉' then 1 else 0 end),
    北京=sum(case SourceFrom when '北京' then 1 else 0 end),
       FROM article 

解决方案 »

  1.   

    CREATE VIEW tgtj
    AS 
     SELECT 
        杭州=sum(case SourceFrom when '杭州' then 1 else 0 end),
        武汉=sum(case SourceFrom when '武汉' then 1 else 0 end),
        北京=sum(case SourceFrom when '北京' then 1 else 0 end),
           FROM article
      

  2.   

    无论是2000, 还是现在的2005, 如果 article 中的 SourceFrom 是不确定的, 都无法用视图直接写出楼主要求的查询.
      

  3.   

    --测试环境
    create table city
    (城市名 nvarchar(50))
    insert city
    select '杭州' union all
    select '武汉' union all
    select '武汉' union all
    select '沈阳' union all
    select '杭州' union all
    select '大连' union all
    select '杭州' union all
    select '北京' union all
    select '大连' union all
    select '沈阳' 
    go
    select * from city
    go
    --查询语句
    create view v_city
    as
    select 城市名,count(城市名) as 出现次数
    from city 
    group by 城市名
    ---结果----
    城市名  出现次数
    北京 1
    大连 2
    杭州 3
    沈阳 2
    武汉 2