SQL筛选最大值的函数是:MAX
例如,求表A中字段B的最大值,B为数字列,语句如下:
select max(B) as Max_B from A延伸:
求B的最小值
select min(B) as Min_B from A求B的平均值
select avg(B) as Avg_B from A看你的要求似乎是要求两个集合的并集,类似下面的方法
select username, Title from Users inner join topic on usersuserid=topicuserid --这是发表的
union all
select username,title from Users inner join reply on UsersUserid=ReplyUserid inner join topic
on topictitleid=replytitleid --这是参与回复的
Create Function RmGetPY(@chn nchar(1))
returns char(1)
as
begin
declare @n int
declare @c char(1)
set @n = 63
select @n = @n +1,@c = case chn when @chn then char(@n) else @c end from(
select top 27 from (
select chn =
'吖' union all select
'八' union all select
'嚓' union all select
'咑' union all select
'妸' union all select
'发' union all select
'旮' union all select
'铪' union all select
'丌' union all select
'丌' union all select
'咔' union all select
'垃' union all select
'呒' union all select
'拏' union all select
'噢' union all select
'妑' union all select
'七' union all select
'呥' union all select
'仨' union all select
'他' union all select
'屲' union all select
'屲' union all select
'屲' union all select
'夕' union all select
'丫' union all select
'帀' union all select @chn) as a
order by chn COLLATE Chinese_PRC_CI_AS
) as b
return(@c)
end
go
Create Function GetAllPY(@chn nvarchar(100))
returns varchar(30)
as
begin
declare @i int,@j int,@result varchar(100)
set @result=''
set @i=len(@chn)
set @j=1
while @j<=@i
begin
set @result = @result + dboRmGetPY(substring(@chn,@j,1))
set @j=@j+1
end
--将助记码限定在30个字母之内
select @result=(case when len(@result)>30 then left(@result,30) else @result end)
return @result
end
先加这两个函数,然后
select from table where dboGetAllPY(字段) like 'J%'
以上就是关于数据库 sql 筛选一个表内相同字段的最大值全部的内容,包括:数据库 sql 筛选一个表内相同字段的最大值、SQL数据库三个表里筛选语句问题、在SQL数据库中,按照英文首字母对数据库中的汉字进行筛选等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)