Выберите из команды select with case и union all

Когда я выполняю запрос

SELECT Settlement_Fees.Participant_Name, Settlement_Fees.Account, Settlement_Fees.Billing_Account, Settlement_Fees.Descr1, Settlement_Fees.Market, Settlement_Fees.Instrum
--, IIf(Settlement_Fees.Instr_Type='Internal','bsinternal',Settlement_Fees.Instr_Type) AS Expr1
,(case when Settlement_Fees.Instr_Type='Internal' then 'bsinternal'
  else Settlement_Fees.Instr_Type
 end )
, Settlement_Fees.Country, Settlement_Fees.Nr_Instr_Business_Unit, Settlement_Fees.Nr_Instr_Account, Settlement_Fees.Avg_EUR_Rate, Settlement_Fees.Fee_Amount_EUR, Settlement_Fees.Value_Date_Adj
FROM Settlement_Fees)
union all
 (select '','',Billing_Account,'','','',
( case when Instr_Type like '%Bridge%' or Instr_Type = '%Internal%' then 'Bszridge/Internal'
else  Instr_Type
end )
 ,'','',Nr_Instr_Account  ,'',Fee_Amount_EUR ,'' 
from Settlement_Fees group by Settlement_Fees.Billing_Account,Settlement_Fees.Instr_Type
,Settlement_Fees.Nr_Instr_Account,Fee_Amount_EUR)
union all 
(select '','',Billing_Account,'','','','Total','','',sum(Nr_Instr_Account),'',sum(Fee_Amount_EUR) ,''
from Settlement_Fees group by Billing_Account

Он работает нормально

, но когда я выполняю с выбором * из (), он дает мне ошибку "Msg 102, Level 15, State 1, Line 33 Неправильный синтаксис рядом с ')' ". для следующего запроса

SELECT *
FROM  ((SELECT settlement_fees.participant_name,
               settlement_fees.ACCOUNT,
               settlement_fees.billing_account,
               settlement_fees.descr1,
               settlement_fees.market,
               settlement_fees.instrum
               --, IIf(Settlement_Fees.Instr_Type='Internal','bsinternal',Settlement_Fees.Instr_Type) AS Expr1
               ,
               ( CASE
                   WHEN settlement_fees.instr_type = 'Internal' THEN
                   'bsinternal'
                   ELSE settlement_fees.instr_type
                 END ),
               settlement_fees.country,
               settlement_fees.nr_instr_business_unit,
               settlement_fees.nr_instr_account,
               settlement_fees.avg_eur_rate,
               settlement_fees.fee_amount_eur,
               settlement_fees.value_date_adj
        FROM   settlement_fees)
       UNION ALL
       (SELECT '',
               '',
               billing_account,
               '',
               '',
               '',
               ( CASE
                   WHEN instr_type LIKE '%Bridge%'
                         OR instr_type = '%Internal%' THEN 'Bszridge/Internal'
                   ELSE instr_type
                 END ),
               '',
               '',
               nr_instr_account,
               '',
               fee_amount_eur,
               ''
        FROM   settlement_fees
        GROUP  BY settlement_fees.billing_account,
                  settlement_fees.instr_type,
                  settlement_fees.nr_instr_account,
                  fee_amount_eur)
       UNION ALL
       (SELECT '',
               '',
               billing_account,
               '',
               '',
               '',
               'Total',
               '',
               '',
               SUM(nr_instr_account),
               '',
               SUM(fee_amount_eur),
               ''
        FROM   settlement_fees
        GROUP  BY billing_account)) 
-121--854219- PHP Сортировка многомерного массива по количеству предметов У меня есть массив, например: Array ([DEF] = > Массив ([0] = > Массив ([type] = > 1 [id] = > 1212...

У меня есть массив, такой как:

Array
(
    [DEF] => Array
        (
            [0] => Array
                (
                    [type] => 1
                    [id] => 1212
                    [name] => Jane Doe
                    [current] => 1
                )

            [1] => Array
                (
                    [type] => 1
                    [id] => 3123121
                    [name] => Door
                    [current] => 
                )
        )

    [ABC] => Array
        (
            [0] => Array
                (
                    [type] => 1
                    [id] => 1234
                    [name] => John Doe
                    [current] => 
                )
        )

    [WW] => Array
        (
            [0] => Array
                (
                    [type] => 1
                    [id] => 1212
                    [name] => Jane Doe
                    [current] => 1
                )

            [1] => Array
                (
                    [type] => 1
                    [id] => 3123121
                    [name] => Door
                    [current] => 
                )

            [2] => Array
                (
                    [type] => 1
                    [id] => 64646
                    [name] => Floor
                    [current] => 
                )
        )
)

И я хочу отсортировать этот массив по числу (count ()) предметов внутреннего массива по убыванию (т.е. большинство предметов в первую очередь), так что я буду иметь этот массив:

Array
(
    [WW] => Array
        (
            [0] => Array
                (
                    [type] => 1
                    [id] => 1212
                    [name] => Jane Doe
                    [current] => 1
                )

            [1] => Array
                (
                    [type] => 1
                    [id] => 3123121
                    [name] => Door
                    [current] => 
                )

            [2] => Array
                (
                    [type] => 1
                    [id] => 64646
                    [name] => Floor
                    [current] => 
                )
        )

    [DEF] => Array
        (
            [0] => Array
                (
                    [type] => 1
                    [id] => 1212
                    [name] => Jane Doe
                    [current] => 1
                )

            [1] => Array
                (
                    [type] => 1
                    [id] => 3123121
                    [name] => Door
                    [current] => 
                )
        )

    [ABC] => Array
        (
            [0] => Array
                (
                    [type] => 1
                    [id] => 1234
                    [name] => John Doe
                    [current] => 
                )
        )
)

Может ли кто-нибудь предложить эффективный способ сделать это? Спасибо.

26
задан Aviram 15 September 2011 в 15:39
поделиться