みなさん、こんにちは。
私は持っています :-
SELECT MAX(register_number) AS "Next-6-months-register-number"
FROM gypsum WHERE test_frequency ='6'
同じクエリのtest_frequency ='3'
との値を返したいのですが、これは可能ですか?'12'
GWSに感謝します。
はい、可能です。GROUP BY
各グループの最大値を取得するために使用します。
SELECT test_frequency, MAX(register_number) AS "Max-register-number"
FROM gypsum
WHERE test_frequency IN ('3', '6', '12')
GROUP BY test_frequency
ORキーワードを使用して追加のパラメーターを追加するだけでよいはずです。
SELECT MAX(register_number) AS "Next-6-months-register-number" FROM gypsum
WHERE test_frequency ='6'
or
test_frequency ='3'
or
test_frequency ='12'
ここで、テスト頻度を追加します..('3','12).. または次のようなクエリから選択します。
SELECT test_frequency, MAX(register_number) AS "Max-register-number"
FROM gypsum
WHERE test_frequency IN ('3','12')
GROUP BY test_frequency
SELECT test_frequency, MAX(register_number) AS "Max-register-number"
FROM gypsum
WHERE test_frequency IN (select frequency_colname from tablename where colname=value)
GROUP BY test_frequency
SELECT
MAX(CASE WHEN test_frequency = '3' THEN register_number END)
AS "Next-3-months-register-number",
MAX(CASE WHEN test_frequency = '12' THEN register_number END)
AS "Next-12-months-register-number",
MAX(CASE WHEN test_frequency = '6' THEN register_number END)
AS "Next-6-months-register-number",
MAX(register_number) AS "Next-6-months-register-number"
FROM gypsum
これを試して
SELECT MAX(CASE
WHEN test_frequency ='6' THEN register_number
ELSE NULL END) AS "Next-6-months-register-number" ,
MAX(CASE
WHEN test_frequency ='3' THEN register_number
ELSE NULL END) AS "Next-3-months-register-number" ,
MAX(CASE
WHEN test_frequency ='12' THEN register_number
ELSE NULL END) AS "Next-12-months-register-number"
FROM gypsum
すべての test_frequency の最大値を取得するには
SELECT test_frequency ,MAX(register_number) AS "Next-6-months-register-number"
FROM gypsum
group by test_frequency
また
SELECT MAX(register_number) AS "Next-6-months-register-number"
FROM gypsum WHERE test_frequency in('6','3','12')
group by test_frequency