问题:
数据库表test 只有一个属性num test{num}
求num的最大值(不能用Max)
解答
1 select ta.num,tb.num from test as ta ,test as tb where ta.num<tb.num
得到的结果是 两个两列的结果集 ,第一列小于第二列
除了最大的数外,其他的数都会出现在第一列中
2 select tc.num from test as tc where tc.num not in
(select ta.num from test as ta ,test as tb where ta.num<tb.num)
从test表中找到num不在1结果集中的那一项,这一项的num属性就是表中num的最大值
///////////////////////////////////////////补充一个其他的小问题///////////////////////////////
select * from table where column = null;//该写法错误
这个语句本意是想找出column列为null的所有项
但是问题是column=null不能判断出其是否等于null(即使column就是null) column=null返回的很可能是unknown值
所以正确的写法是
select * from table where column is null;
select * from table where column is not null;
本文将展示如何通过子查询和条件过滤来解决SQL问题,具体实例为在数据库表中寻找单一属性的最大值,同时讨论了避免使用Max函数的方法,并提供了两种解决方案。此外,文章还探讨了如何正确使用NULL值的判断方法。
785

被折叠的 条评论
为什么被折叠?



