SQL语法怎么取得一个字段的最大值

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SQL语法怎么取得一个字段的最大值相关的知识,希望对你有一定的参考价值。

SQL即结构化查询语言(Structured Query Language),是一种特殊目的的编程语言,是一种数据库查询和程序设计语言,用于存取数据以及查询、更新和管理关系数据库系统;

SQL语句,获取一个字段的最大值可以使用max()

MAX 函数返回一列中的最大值。NULL 值不包括在计算中。

SQL MAX() 语法:

SELECT MAX(column_name) FROM table_name

注:MAX 也可用于文本列,以获得按字母顺序排列的最高或最低值。

SELECT 语句用于从表中选取数据。结果被存储在一个结果表中(称为结果集)。

数据内容:

执行结果:

参考技术A 这是一个最基本的函数啊
select max(字段名) from 表名
参考技术B 可以描述清楚点吗? 查询记录中某列的最大值使用聚合函数MAX,还有其他的聚合函数,如Count,svg ,min等 各有用法,可以百度下。 参考技术C select max(字段) from table 参考技术D select max(字段) from tablename

postgresql数据库中,查询一个字段允许的最大长度的SQL语句怎么写?

select
relname as 表名,
attname as 列名,
attnum as 列号,
case typname
when '_bpchar' then 'char'
when '_varchar' then 'varchar'
when '_date' then 'date'
when '_float8' then 'float8'
when '_int4' then 'integer'
when '_interval' then 'interval'
when '_numeric' then 'numeric'
when '_float4' then 'float4'
when '_int2' then 'smallint'
when '_text' then 'text'
when '_time' then 'time'
when '_timestamp' then 'timestamp'
end as 类型,
case typname
when '_bpchar' then atttypmod - 4
when '_varchar' then atttypmod - 4
when '_numeric' then (atttypmod - 4) / 65536
else attlen
end as 长度,
case typname
when '_numeric' then (atttypmod - 4) % 65536
else 0
end as 小数

from pg_stat_user_tables as a,
pg_attribute as b,
pg_type as c
where schemaname='u1'
and relname='t1'
and a.relid=b.attrelid
and b.attnum>0
and b.atttypid=c.typelem
and substr(typname,1,1)='_'
order by schemaname,relname,attnum;

where条件的地方 自己适当删减
参考技术A 对于character类型和character varying类型的字段,也可以用一下语句查询。
SELECT
attname as "name", typname as "type", atttypmod - 4 as "size"
FROM
pg_class AS a
LEFT OUTER JOIN pg_attribute AS b ON (b.attrelid = a.oid)
LEFT OUTER JOIN pg_type AS c ON (b.atttypid = c.oid)
where a.relname = '<tablename>' and attname='<fieldname>'
and b.attstattarget = -1
order by attnum;
希望对你有所帮助。本回答被提问者采纳

以上是关于SQL语法怎么取得一个字段的最大值的主要内容,如果未能解决你的问题,请参考以下文章

SQL(oracle) 取得分组后最大值记录

SQL中如何取多列的最大值?

mssql 2005查询 请问我要实现分组获取最大值,怎么写sql查询指令

mysql数据库中sql修改字段类型要怎么做

数据库查询每个字段对应的最大值

sql查询时间最小值的列