举个例子, 以下2句可以合并吗? 否则要执行2次子查询.with t as
(select * from t1)
select count(*) from t;with t as
(select * from t1)
select * from t

解决方案 »

  1.   


    with t as
    (select * from t1)
    select *,(select count(*) from t) cc from t;
      

  2.   

    select *,count(*)over() from t1
      

  3.   

    with t as
    (select * from t1)
    select t.* , (select count(*) from t) from t 
      

  4.   

    这样?with t1 as
    (select * from t1)
    , t2 as
    (select * from t1)
    select * from t2,(select count(*) con from t1)t1
    过多CTE引号效率不高,不如直接用临时表代替
      

  5.   

    --2000
    SELECT  *
    FROM    t1 ,
            ( SELECT    COUNT(*) rn
              FROM      t1
            ) b
            --2005
    SELECT  * ,
            COUNT(*) OVER ( ) rn
    FROM                    t1
      

  6.   

    你要实现的功能,没有任何更高效率的语法可以代替。
    t-sql写的啰嗦并不代表性能差,而一句能完成的sql,也并不代表性能高,而且往往很差。