3

みなさん、こんにちは。

私は持っています :-

 SELECT MAX(register_number) AS "Next-6-months-register-number" 
    FROM gypsum WHERE test_frequency ='6'

同じクエリのtest_frequency ='3'との値を返したいのですが、これは可能ですか?'12'GWSに感謝します。

4

6 に答える 6

5

はい、可能です。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
于 2012-10-15T12:57:56.820 に答える
0

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'
于 2012-10-15T12:59:13.283 に答える
0

ここで、テスト頻度を追加します..('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
于 2012-10-15T13:07:16.757 に答える
0
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 
于 2012-10-15T12:58:22.157 に答える
0

これを試して

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
于 2012-10-15T12:58:30.620 に答える
0

すべての 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 
于 2012-10-15T12:58:59.987 に答える