派生列を別のプロシージャの入力として使用することで、このクエリを簡略化できますか?
$query = "SELECT table1.id,
COUNT(DISTINCT arr1.element) AS Arr1,
COUNT(DISTINCT arr2.element) AS Arr2,
COUNT(DISTINCT arr1.element) +
COUNT(DISTINCT arr2.element) AS tot,
(COUNT(DISTINCT arr1.element)/(COUNT(DISTINCT arr1.element)+COUNT(DISTINCT arr2.element)))*col3 AS c31,
(COUNT(DISTINCT arr2.element)/(COUNT(DISTINCT arr1.element)+COUNT(DISTINCT arr2.element)))*col3 AS c32
FROM table1
WHERE col2 = 'x'"
このようなもの
$query = "SELECT table1.id,
COUNT(DISTINCT arr1.element) AS Arr1,
COUNT(DISTINCT arr2.element) AS Arr2,
COUNT(DISTINCT arr1.element) +
COUNT(DISTINCT arr2.element) AS tot,
(Arr1/tot)*col3 AS c31,
(Arr2/tot)*col3 AS c32
FROM table1
WHERE col2 = 'x'"
ありがとう