0

次のSQLクエリがあります。すべての行数を取得したい。誰でも私を助けることができますか?

WITH numberedrows 
     AS (SELECT DISTINCT TOP 10 f_feeid_pk, 
                                f_code, 
                                f_description, 
                                f_fee, 
                                f_areaid_ind_fk, 
                                a_name_ind, 
                                p_name_ind, 
                                s_name_ind, 
                                b_name_ind, 
                                Row_number() 
                                  OVER ( 
                                    ORDER BY b_name_ind, s_name_ind, p_name_ind, 
                                  a_name_ind, f_code ASC) AS 
                                RowNumber 
         FROM   t_fee 
                INNER JOIN t_area 
                        ON f_areaid_ind_fk = a_areaid_pk 
                INNER JOIN t_project 
                        ON a_projectid_fk = p_projectid_pk 
                INNER JOIN t_section 
                        ON p_sectionid_fk = s_sectionid_pk 
                INNER JOIN t_branch 
                        ON s_branchid_fk = b_branchid_pk 
         WHERE  f_feeid_pk > 0) 
SELECT * 
FROM   numberedrows 
4

1 に答える 1

2

個別の数のみに関心があると仮定して、それをすべての個別の結果を取得するには、それDISTINCT TOP 10を置き換えます。それ以外の場合は DISTINCT も削除してから、オーバー CTE を使用するように変更します。DISTINCTSELECTCOUNT(*)

WITH numberedrows 
     AS (SELECT DISTINCT f_feeid_pk, 
                                f_code, 
                                f_description, 
                                f_fee, 
                                f_areaid_ind_fk, 
                                a_name_ind, 
                                p_name_ind, 
                                s_name_ind, 
                                b_name_ind, 
                                Row_number() 
                                  OVER ( 
                                    ORDER BY b_name_ind, s_name_ind, p_name_ind, 
                                  a_name_ind, f_code ASC) AS 
                                RowNumber 
         FROM   t_fee 
                INNER JOIN t_area 
                        ON f_areaid_ind_fk = a_areaid_pk 
                INNER JOIN t_project 
                        ON a_projectid_fk = p_projectid_pk 
                INNER JOIN t_section 
                        ON p_sectionid_fk = s_sectionid_pk 
                INNER JOIN t_branch 
                        ON s_branchid_fk = b_branchid_pk 
         WHERE  f_feeid_pk > 0) 
SELECT COUNT(*) FROM numberedrows;
于 2012-10-12T06:18:38.710 に答える