问1道华为面试题

lainY7mail 2008-03-31 10:53:54
1.求 a(num int) 表的最大值,不能用max(),有几种方法


...全文
1166 54 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
54 条回复
切换为时间正序
请发表友善的回复…
发表回复
wh110 2008-04-03
  • 打赏
  • 举报
回复
select * from ta a where not exists(select 1 from ta where num> a.num)
zy227 2008-04-02
  • 打赏
  • 举报
回复
星星太多了 牛人 小聚義??
chenhongxin 2008-04-01
  • 打赏
  • 举报
回复
--6
declare @num1 int
update @a
set @num1=case when @num1 is null then num
when @num1<num then num
else @num1
end
select @num1
lainY7mail 2008-04-01
  • 打赏
  • 举报
回复
看来CSDN 的牛人真的太多了
继续学习
zanyzyg 2008-04-01
  • 打赏
  • 举报
回复

哈哈

太拽了


you_tube 2008-04-01
  • 打赏
  • 举报
回复
select min(-1*num)*-1 from a

-------------------------------

这个牛到家了
wugencao520 2008-04-01
  • 打赏
  • 举报
回复
比较常规的还是会选 top 1 这个方法把!
xfjds1987 2008-04-01
  • 打赏
  • 举报
回复
华为那种猪脑袋的面试官,没法...这种无聊的面试题都能出。所谓从面试官可看公司..
拉文麦克 2008-03-31
  • 打赏
  • 举报
回复
哈哈,错了
拉文麦克 2008-03-31
  • 打赏
  • 举报
回复
不能用max就用min
select min(num) from a
lainY7mail 2008-03-31
  • 打赏
  • 举报
回复
学习了 学习了
当时我就只知道 select top 1 的那种方法
yyyyzzzz_2002 2008-03-31
  • 打赏
  • 举报
回复
if object_id('tempdb..#') is not null
drop table #
create table #(num int not null)

insert into #
select 1
union all
select 2
union all
select 3
union all
select 4
union all
select 5
union all
select 5

--1
select top 1 num
from #
order by num desc
--2
select distinct num
from # a
where not exists(select top 1 1
from # where num>a.num)
--3

declare @i int
declare @temp int
declare @max int
set @i=0
set @temp=0
set @max=0
declare cur cursor local for
select num from #
open cur
fetch next from cur into @i
while @@fetch_status=0
begin
set @temp = @i
if(@temp>@max)
set @max=@temp
else
set @max=@max
fetch next from cur into @i
end
select @max
close cur
deallocate cur

xiao_yi 2008-03-31
  • 打赏
  • 举报
回复
or pro .... another method......
utpcb 2008-03-31
  • 打赏
  • 举报
回复
可能考试思维吧 ,TOP ORDER BY ,冒泡排序 ,==排序算法 我觉得他们就考我们算法的
wangxuelid 2008-03-31
  • 打赏
  • 举报
回复
[Quote=引用 15 楼 Haiwer 的回复:]
估计华为考官想不到这么多了,不再想了
[/Quote]
晕呢,,,可能是不想常规那样出题而已,试人员的综合水平
wzy_love_sly 2008-03-31
  • 打赏
  • 举报
回复
怪不得老跳楼,连面试的也这样....
viva369 2008-03-31
  • 打赏
  • 举报
回复
华为的人真命苦
昵称被占用了 2008-03-31
  • 打赏
  • 举报
回复
估计华为考官想不到这么多了,不再想了
昵称被占用了 2008-03-31
  • 打赏
  • 举报
回复

--6
declare @num1 int
update @a
set @num1=case when @num1 is null then num
when @num1<num then num
else @num1
end
select @num1
dawugui 2008-03-31
  • 打赏
  • 举报
回复
[Quote=引用楼主 lainY7mail 的帖子:]
1.求 a(num int) 表的最大值,不能用max(),有几种方法
[/Quote]

难怪华为招不到人.

你能不能问问他,为什么不用这个最好的方法,反而吃饱了没事干去追求其他的方法?

加载更多回复(34)

34,838

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧