大家好,数据库里面有20多个表,每个表里面只有1列都是数字,数字要被写入的,我想查看这所有表里面的最小值是什么,请问这个语言怎么写呢?用视图 还是用什么呢~~ 谢谢各位高手咯~~
解决方案 »
- SQL2008里面视图无法order by?
- check语句在MS SQL中怎么写?
- 我有1000条数据请问用TOP怎么取出200-300之间的数据
- 如何将数据表中字段描述内容在导出数据表的时候导入到新表中?
- 问你一个比较郁闷的更新问题啊,sql语句的,在线急等!!!!!!!!!!!!!!!!
- ADO查询两次变成很慢(假死状态)
- zc_0101兄请进!
- 谁有sql便携版,急需啊!!
- 函数,存储过程嵌套问题
- 求一句 SQL,得到 全班人名,谢谢!
- 语句 alter table A add px int identity(1,1)是什么意思?
- |zyciis| 面试公司出的题:一个员工表和会员表的设计,我的设计和面试人员不同,他不同意我的设计,我也不同意他的设计,大家来分表一个看法 谢谢
from
(select 数字列 from 表1
union all
select 数字列 from 表2
union all
select 数字列 from 表3
union all
select 数字列 from 表4
)t
exec sp_msforeachtable 'insert TempTable(t) select min(ColName) from ?',@whereand=' and name <>''TempTable'''
select min(t) from TempTable
drop table TempTable
select min(数字列)
from
(select min(数字列)数字列 from 表1
union all
select min(数字列) from 表2
union all
select min(数字列) from 表3
union all
select min(数字列) from 表4
)t
用了 显示 消息 209,级别 16,状态 1,第 1 行
列名 'name' 不明确。
方法很牛~~ 也谢谢其他朋友哈~~
declare @i int
declare @j int
declare @sql Nvarchar(4000)
declare @name Nvarchar(50)
set @j=-1
declare cur cursor for
select name from sys.objects where type='U'open cur
fetch next cur into @namewhile @@fetch_status=0
begin
set @sql=N'select @i=min(id) from ['+@name+']'--id为数字列
exec sp_executesql @sql,N'@i int output',@i output
if(@i<@j)
@j=@i fetch next cur into @name
end
close cur
deallocate cur
select @j