比如说要统计表abc中a字段不重复的条数:先创建一个视图1
select distinct a form abc
select count(a) as a之count from 视图1上面过程用一条SQL能解决吗?

解决方案 »

  1.   


    select count(a) as a之count 
    from (select distinct a form abc) as T
      

  2.   

    Select count(distinct a) as cn form abc
      

  3.   

    --用子查询
    -楼主,你的from写成form了!select count(a) as a之count 
    from (select distinct a from abc) as T
      

  4.   

    select [a之count]=count(distinct a) form abc--这样就行了
      

  5.   

    select [a之count]=count(distinct a) from abc--这里的form 表单改为from
      

  6.   

    select count(distinct a) as [a之count] from abc
      

  7.   

    select count(distinct a)form abc
      

  8.   

    多谢各位回复,还有个问题,用这样可以
    select [a之count]=count(distinct a) from abc
    但我在存储过程中把它赋值给一个变量就不行,显示:在关键字 'FROM' 附近有语法错误。这是为什么?
    set @a=count(distinct a) from abc
      

  9.   

    select @a=count(distinct a) from abc
      

  10.   

    declare @a intselect @a=count(distinct a) from abc--或set @a=(select count(distinct a) from abc)