私は現在、会計用にmysqlとopenreportsを使用してレポートを最適化しようとしています。その仕事にはもっと良いツールがあると確信していますが、これらは私が現時点で使用しなければならないものです。私は次の計算フィールドを実行しています。
クライアント、注文数、クライアントコスト、クライアント調整、調整済みクライアント価格(クライアントコスト-クライアント調整)、ベンダーコスト、ベンダー調整、調整済みベンダー価格(ベンダーコスト-ベンダー調整)、マージン((クライアント請求-ベンダー請求)/クライアント請求)、adjマージン((adjクライアント価格-adjベンダー価格)/ adjクライアント)
テーブルは非常に大きく、内部結合ごとに4つのテーブルを結合する必要があります。以前に作成されたレポートには、ユニオンがあり、ユニオンの両側に約20のネストされた選択があり、すべてに少なくとも4つの結合とカウントが含まれています。以前のフィールドに基づいて計算を行っているため、ネストされた各選択は、ネストされた選択、カウント、および以前の計算からの計算のすべてを含めて、徐々に大きくなります。クエリは現在400行で、特に大規模なクライアントでは非常に高価でシステムに負担がかかります。
私はその仕事のためのより良いツールがあることを知っていますが、私はその状況のための理想的な解決策は何であるかと思っていました。クエリ内にユーザー定義変数を作成し、後で使用できますか?クライアントごとに複数のクエリがある場合、これは機能しますか?この投稿に400行のクエリ全体を含めることはできませんが、役立つと思われる追加の詳細を提供することはできます。任意の洞察をいただければ幸いです。
select office_1.name as 'Client'
,count(distinct(property_1.id)) as 'Total Billed Orders',
(select format(coalesce(sum(serviceprice_2.amount),0),2)
from cap.service_price serviceprice_2
inner join cap.service service_2 on service_2.id = serviceprice_2.service_id
inner join cap.service_area servicearea_2 on servicearea_2.id = service_2.service_area_id
inner join cap.property property_2 on property_2.id = servicearea_2.property_id
inner join cap.office office_2 on office_2.id = property_2.client_id
where serviceprice_2.price_context = 'CLIENT'
and serviceprice_2.price_type_id = 236
&& service_2.date_client_billed between '2012-09-01' and now()
and service_2.gl_code_ap='4700-70-000'
and service_2.date_cancelled is null
and office_2.id = office_1.id) as 'Client Price'
/* other calculations between here */
from cap.service service_1
inner join cap.service_area servicearea_1 on servicearea_1.id = service_1.service_area_id
inner join cap.property property_1 on property_1.id = servicearea_1.property_id
inner join cap.office office_1 on office_1.id = property_1.client_id
inner join cap.office vendor_1 on vendor_1.id = service_1.vendor_id
where
service_1.date_client_billed between '2012-09-01' and now()
and service_1.date_cancelled is null
and office_1.id = 26377
and service_1.gl_code_ap='4700-70-000'
group by office_1.id
;