选择min,max,avg,WHERE

时间:2012-10-18 12:47:29

标签: mysql sql where

我正在使用MySQL。

我正在尝试选择字段的最小,最大和平均长度,但我不确定如何。像这样:

SELECT 
  min as min,
  max as max,
  avg as avg
FROM COLUMNS
WHERE COLUMN_NAME like '%password%'

有什么想法吗?

3 个答案:

答案 0 :(得分:7)

select
    column_name,
    min(length(column_name)) as min,
    max(length(column_name)) as max,
    avg(length(column_name)) as avg
from columns
where column_name like '%password%'
group by column_name

答案 1 :(得分:2)

SELECT Min(COLUMN_NAME), 
       Max(COLUMN_NAME), 
       Avg(COLUMN_NAME) 
  FROM TABLENAME 
 WHERE COLUMN_NAME LIKE '%password%' 

答案 2 :(得分:0)

SELECT Min(MENTION_COLUMN_NAME_HERE) AS minimum_value, 
       Max(MENTION_COLUMN_NAME_HERE) AS maximum_value, 
       Avg(MENTION_COLUMN_NAME_HERE) AS average_value 
  FROM COLUMNS 
 WHERE COLUMN_NAME LIKE '%passord%'