当前位置:首页 » 编程语言 » sql怎么取指定行的值
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

sql怎么取指定行的值

发布时间: 2022-04-02 18:21:21

1. sql 获取某一行某一列的值

SQL里面只有列才是条件 如果你表里面有主键(比如说ID)的话那就好找

select 列名 from table_name where ID=?

就可以确定了

2. sql 选取某列某行的值

就算不是 union all 结果集,SQL语句也无法直接实现你要的效果。
只有做存储过程,声明变量,分别保存第一行和第二行的数据,进行运算,输出结果。

3. 数据库读取数据如何读取指定特定的几行

select * from [table] where id between 3 and 8
这样取的是3-8之间的行数据

4. SQL 如何取出每一行字段的值不同的行

先列转行在查询
select* from tablea_3
NO A B C D E F G
a 1 0 0 0 1 0 0
c 0 0 0 0 0 0 0
b 3 2 0 0 1 3 2

declare @s varchar(8000)------------------------------------------先列转行
set @s = 'create table tablea_32 (no varchar(20)'
select @s = @s + ',' + no + ' varchar(10)' from tablea_3
set @s = @s + ')'
exec(@s)
print @s
--借助中间表实现行列转换
declare @name varchar(20)

declare t_cursor cursor for
select name from syscolumns
where id=object_id('tablea_3') and colid > 1 order by colid

open t_cursor

fetch next from t_cursor into @name

while @@fetch_status = 0
begin
exec('select ' + @name + ' as t into tablea_33 from tablea_3')
set @s='insert into tablea_32 select ''' + @name + ''''
select @s = @s + ',''' + rtrim(t) + '''' from tablea_33
exec(@s)
exec('drop table tablea_33')
fetch next from t_cursor into @name
end
close t_cursor
deallocate t_cursor

--查看行列互换处理结果

select * from tablea_32
declare @a int
declare @b int
declare @c char(10)

select @a= min( ascii(no)) from tablea_32

select @b= max( ascii(no)) from tablea_32

while (@a<=@b)
begin

set @c=char(@a)

insert into #A
select distinct a,no
from tablea_32 where no=@c and a<>0

insert into #B
select distinct B,no
from tablea_32 where no=@c and B<>0

insert into #C
select distinct C,no
from tablea_32 where no=@c and C<>0
set @a=@a+1
end

if exists ( select count(distinct A) from #a having count(distinct a)>1)
PRINT 'A'

if exists ( select count(distinct B) from #B having count(distinct B )>1)
print 'B'

if exists ( select count(distinct C) from #C having count(distinct C )>1)
print 'C'

5. SQL Server如何取得某一列中的某一行数据

SQL Server如何取得某一列中的某一行数据?
按你的意思查询出来的只是一个值,列与行的交叉只有一个数据.

SELECT [列名] FROM [表名] WHERE [列名]=值

如果要显示某列数值
SELECT [列名] FROM [表名]

如果显示某列值为定值时的一行
SELECT * FROM [表名] WHERE [列名]=已知值

6. 【SQL语句】如何从查询的结果中获取指定行

如果你是MySQL的话:select x1,y1 from tb_Load where x2=22 and y2=77 limit 3,1

7. sql server数据库如何抽取指定行列的数据

with t as(
select * ,row_number() over(order by getdate()) as bz
from tablename )
select * from t where bz=..

你想要第几row,就让bz 等于几了。
一般不会有人问第几column,直接看下表,你选取那个字段就好了

8. sql server如何抽取指定行列的数据,最好写出抽取的语句

with t as(
select * ,row_number() over(order by getdate()) as num
from tablename )
select * from t where num=3
上述例子,num=3就是指取第三条,要抽取其他行,手工调整此数即可,其实SQL Server没有指定行号、列号的取数方法,给的例子是按记录插入表的顺序抽取

9. sql2008怎样获取指定行的数据谢谢

方法1:
SELECT * FROM 表 WHERE id >= 8 AND id <= 15

方法2:
SELECT TOP 8 * FROM 表 ORDER BY id DESC

10. SQL中如何获取满足某一条件的行中的某个值

declare @st char(255)
select @st=C from tb where A=20