大家好,
我有 :-
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
在这里,您添加测试频率..('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
您应该能够使用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'