按我的理解,OVER是用于对聚合函数进行分区或排序的,但是一个空的OVER()有什么用呢?下面的2句得出的结果不一样,求高人解答.先谢过哈
  
1. select lastname, (COUNT(*)*1.0)/COUNT(*) as percentage from CurrentStudents group by lastname
  
2. select lastname, (COUNT(*)*1.0)/COUNT(*) over() as percentage from CurrentStudents group by lastname

解决方案 »

  1.   

    select lastname,
     COUNT(*),
    COUNT(*) over(),

     (COUNT(*)*1.0)/COUNT(*) as percentage from CurrentStudents group by lastname 
    这样你看看就明白了
      

  2.   

    over 和 group by 用在一起有啥意义呢?
      

  3.   

    你这里的count(*) over() 得到的值是你group by 之后得到的总行数的值
      

  4.   

    查下SQL的开窗函数,自己理解下.
    你直接over可以不用再后面加group by.
      

  5.   

    if object_id('tb') is not null
    drop table tb
    go
    create table tb(id int identity(1,1) primary key,name1 varchar(10))
    insert into tb(name1)
    select 'zzzz' union all
    select 'zzzz' union all
    select 'zzgg' union all
    select 'zzgg' union all
    select 'zzgg' union all
    select 'zzgg' union all
    select 'gggg' union all
    select 'gggg' union all
    select 'gggg' union all
    select 'zzzz' 
    select count(*),count(*) over() from tb group by name1
    结果:
    3 3
    4 3
    3 3
      

  6.   

    OVER()?太多用处了 查询联机丛书
    row_number()
    dense_rank()
    排名函数都需要
      

  7.   

    根據5樓的例子就很容易看出來,,,如果還看不懂
    運行完他的代碼后在,,
    insert into tb(name1)
    select 'zz11' union all
    select 'zz11' 
    select count(*),count(*) over() from tb group by name1 
    再看結果
    還不懂再添加,,,不同行,,,
      

  8.   

    知道了,原来
    2. select lastname, (COUNT(*)*1.0)/COUNT(*) over() as percentage from CurrentStudents group by lastname 应该理解为
    2. select lastname, (COUNT(*)*1.0)/(COUNT(*) over()) as percentage from CurrentStudents group by lastname 这样就清楚了,谢谢各位!