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

在这里,您添加测试频率..('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 回答
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 回答