如何显示SQL数据库表中某一行某一列的值?

kankan6164 2011-09-19 05:05:30
想要显示表中特定某一行某一列的值,怎么实现?用SQL语句吗?
求明白人解答。
比如,我表名为student,我想得到第二行第二列的值,那select语句应该是
select * from student where....
where往后的条件怎么写?
...全文
6173 14 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
yojinlin 2011-09-20
  • 打赏
  • 举报
回复
友情幫頂。
cjh200102 2011-09-20
  • 打赏
  • 举报
回复
楼主说的不详细,大家都是猜的
ningweidong 2011-09-20
  • 打赏
  • 举报
回复
select语句还不会写吗
q198708wyp 2011-09-20
  • 打赏
  • 举报
回复
纯SQL语句 还是 某个控件? sql 语句 直接 用 那行那列的ID指定九号了啊
krenyelang 2011-09-20
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 wnyxy 的回复:]
sql里只能指定列名吧

你是不是想在datagridview里查啊
绑定数据源后dataGridView1.Rows[1].Cells[1].Value //第二行第二列的值
[/Quote]

赞同……
叶子 2011-09-19
  • 打赏
  • 举报
回复

--楼主说的第二个列是指不知道列名的情况下
create table test(col1 int,col5 int,col6 int)
insert into test
select 1,2,3 union all
select 4,5,6 union all
select 7,8,9

go
create proc GetValueByPos
(
@tablename varchar(50),--表名
@hang int,--行号
@lie int --列号
)
as
begin
declare @liename varchar(50)
declare @sql varchar(8000)
;with m as
(
select name,lie=row_number() over (order by getdate())
from syscolumns where id=object_id(@tablename)
)
select @liename=name from m where lie=@lie
set @sql=
'select row_number() over (order by getdate()) as hang,* into #t from '+@tablename
+char(13)+'select '+@liename+' from #t where hang='+ltrim(@hang)
+char(13)+'drop table #t'
exec(@sql)
end

exec GetValueByPos 'test',2,3

/*
col6
-----------
6
*/

我爱小土豆 2011-09-19
  • 打赏
  • 举报
回复
输入 select 第二列,第三列名字 from student 这样就ok了吧
love_4023 2011-09-19
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 love_4023 的回复:]
SQL code


看是什么数据库吧,如果是oracle得话:Select 列名 From tablename Where rownum =2
如果是mysql的话,Select 列名 From tablename Limit 1,1
如果是sqlServer的话,需要嵌套下Top。
[/Quote]
不好意思oracle不太熟写错了。
love_4023 2011-09-19
  • 打赏
  • 举报
回复

看是什么数据库吧,如果是oracle得话:Select 列名 From tablename Where rownum =2
如果是mysql的话,Select 列名 From tablename Limit 1,1
如果是sqlServer的话,需要嵌套下Top。
funxu 2011-09-19
  • 打赏
  • 举报
回复
刚才多敲了个a 4L是正解
hudenq 2011-09-19
  • 打赏
  • 举报
回复
string sql="select top 1 列名 from(select top 2 列名 from student order by id asc ) order by id desc"
funxu 2011-09-19
  • 打赏
  • 举报
回复
select top 1 列名 from a
(select top 2 列名 from student) as a
order by 列名
desc
  • 打赏
  • 举报
回复
select 第二列的名称 from tablename where 行id=xxoo
wnyxy001 2011-09-19
  • 打赏
  • 举报
回复
sql里只能指定列名吧

你是不是想在datagridview里查啊
绑定数据源后dataGridView1.Rows[1].Cells[1].Value //第二行第二列的值

111,093

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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