表T(A)包含正整数,可能有重复,构造一个SQL语句查询不在表T中的最小正整数,需要考虑表T包含或不包含正整数1两种情况。不能编程实现。考虑了半天没有很好的思路,请大家指点则个
考虑了半天没有很好的思路,请大家指点则个
DECLARE @minvalue INT = select min(A) from T
IF minvalue > 1
return 1
ELSE
DECLARE @maxvalue INT = select max(A) from T
WHILE (minvalue < maxvalue)
BEGIN
if exists(select A from T where A = minvalue)
set minvalue = minvalue + 1
else
return minvalue
end
END
return maxvalue + 1
END
select a.mc ,sum(dj*sl) from table1 a,table2 b
where a.mc = b.mc
group by a.mc
having sum(dj*sl)>sum(b.xj)
create view temp as
select num,ROW_NUMBER() over (order by num) as ord
from postable
go
declare @num int
set @num = 1
while @num >= (select num from temp where ord = @num)
begin
set @num = @num +1
end
print @num
不过老师好像说不能用编程来实现吧?这个Transcant-SQL在postgreSQL运行不了的,应该老师的意思是只能用SQL来写。