

 Amazon Redshift は、パッチ 198 以降、新しい Python UDF の作成をサポートしなくなります。既存の Python UDF は、2026 年 6 月 30 日まで引き続き機能します。詳細については、[ブログ記事](https://aws.amazon.com/blogs/big-data/amazon-redshift-python-user-defined-functions-will-reach-end-of-support-after-june-30-2026/)を参照してください。

# RATIO\$1TO\$1REPORT ウィンドウ関数
<a name="r_WF_RATIO_TO_REPORT"></a>

ウィンドウまたはパーティションの値の合計に対する、ある値の比率を計算します。値を報告する比率は、次の式を使用して特定されます。

`value of `*ratio\$1expression* `argument for the current row / sum of` *ratio\$1expression* `argument for the window or partition`

以下のデータセットは、この式の使用方法を示しています。

```
Row#	Value	Calculation	RATIO_TO_REPORT
1	2500	(2500)/(13900)	0.1798
2	2600	(2600)/(13900)	0.1870
3	2800	(2800)/(13900)	0.2014
4	2900	(2900)/(13900)	0.2086
5	3100	(3100)/(13900)	0.2230
```

戻り値の範囲は、0～1 (0 と 1 を含みます) です。*ratio\$1expression* が NULL である場合、戻り値は `NULL` です。*partition\$1expression* 内の値が一意である場合、関数はその値として `1` を返します。

## 構文
<a name="r_WF_RATIO_TO_REPORT-synopsis"></a>

```
RATIO_TO_REPORT ( ratio_expression )
OVER ( [ PARTITION BY partition_expression ] )
```

## 引数
<a name="r_WF_RATIO_TO_REPORT-arguments"></a>

*ratio\$1expression*   
比率を特定する値を提供する式 (列名など)。式は、数値データ型を含んでいるか、そのデータ型に暗黙的に変換できる必要があります。  
*ratio\$1expression* で他の分析関数を使用することはできません。

OVER  
ウィンドウのパーティションを指定する句。OVER 句にウィンドウの並び順またはウィンドウフレーム仕様を含めることはできません。

PARTITION BY *partition\$1expression*   
省略可能。OVER 句の各グループのレコードの範囲を設定する式。

## 戻り型
<a name="r_WF_RATIO_TO_REPORT-return-type"></a>

FLOAT8

## 例
<a name="r_WF_RATIO_TO_REPORT-examples"></a>

次の例は、WINSALES テーブルを使用しています。WINSALES テーブルを作成する方法については、「[ウィンドウ関数例のサンプルテーブル](c_Window_functions.md#r_Window_function_example)」を参照してください。

次の例では、すべての販売者の数量の合計に対する、各行の販売者の数量の、対レポート比率を計算します。

```
select sellerid, qty, ratio_to_report(qty) 
over()
from winsales
order by sellerid;

sellerid  qty    ratio_to_report
--------------------------------------
1         30     0.13953488372093023	
1         10     0.046511627906976744	
1         10     0.046511627906976744	
2         20     0.09302325581395349	
2         20     0.09302325581395349	
3         30     0.13953488372093023	
3         20     0.09302325581395349	
3         15     0.06976744186046512	
3         10     0.046511627906976744	
4         10     0.046511627906976744	
4         40     0.18604651162790697
```

以下の例では、各販売者の販売数量の比率をパーティションごとに計算します。

```
select sellerid, qty, ratio_to_report(qty) 
over(partition by sellerid) 
from winsales;

sellerid   qty    ratio_to_report
-------------------------------------------
2          20     0.5	
2          20     0.5	
4          40     0.8	
4          10     0.2	
1          10     0.2	
1          30     0.6	
1          10     0.2	
3          10     0.13333333333333333	
3          15     0.2	
3          20     0.26666666666666666	
3          30     0.4
```