怎样得到数据库中某一行的某一列的值?

zhangjidong 2004-08-17 12:52:12
怎样得到数据库中某一行的某一列的值?
...全文
291 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
skyboy0720 2004-08-17
  • 打赏
  • 举报
回复
问得有点怪怪的!!
老宛 2004-08-17
  • 打赏
  • 举报
回复
有主键吗?有的话

select yourcol from yourtable where 主键=你自己填
木一人 2004-08-17
  • 打赏
  • 举报
回复
select identity(int,1,1) as xh,* into #a
from TB
select * from #a where xh=100
AntingZ 2004-08-17
  • 打赏
  • 举报
回复
查询路人乙的年龄:
select 年龄 from 表 where 姓名='路人乙'

查询id=3的人的姓名:
select 姓名 from 表 where id=3

查询年龄为18的人的姓名:
select 姓名 from 表 where 年龄=18
love800309 2004-08-17
  • 打赏
  • 举报
回复
如果查出来是多条记录呢?

我要用非第一条的某个列的值 怎么表示出来

谢谢
chinaandys 2004-08-17
  • 打赏
  • 举报
回复
1.有主键。
2.标识:select 标识=identity(int,1,1),* into #t from 表
select * from #t where 标识=行数
drop table #t
不管怎样都要有自动增量.
  • 打赏
  • 举报
回复
select field1 from yourtable where id=5

:)
yyhyy23 2004-08-17
  • 打赏
  • 举报
回复
select distinct(colname) from tablename where id=变量
ghostone 2004-08-17
  • 打赏
  • 举报
回复
select 字段 from 表名 where 条件

老宛 2004-08-17
  • 打赏
  • 举报
回复
这个问题确实是简单了些,楼主是刚刚接触sql server吧,不过不要紧,以后多来来csdn,技术会很快提高的,共同努力吧!呵呵
skyboy0720 2004-08-17
  • 打赏
  • 举报
回复
如果你要的是这个,建议楼主,还是找本基础书看看吧!
老宛 2004-08-17
  • 打赏
  • 举报
回复
按照你提供的数据应该是

select 姓名 from yourtable where [id]=1
老宛 2004-08-17
  • 打赏
  • 举报
回复
--用select 姓名 from yourtable where [id]=2就可以了


create table #t(
[id] int identity(1,1),
姓名 varchar(10),
年龄 int)

insert into #t select '路人甲',17
insert into #t select '路人乙',18
insert into #t select '路人丙',34


--select 年龄 from #t where [id]=3
select 姓名 from #t where [id]=2

drop table #t
老宛 2004-08-17
  • 打赏
  • 举报
回复
--测试:
create table #t(
[id] int identity(1,1),
姓名 varchar(10),
年龄 int)

insert into #t select '路人甲',17
insert into #t select '666',18
insert into #t select 'qqq',34


select 年龄 from #t where [id]=3
select 姓名 from #t where [id]=3

drop table #t
zhangjidong 2004-08-17
  • 打赏
  • 举报
回复
ID 姓名 年龄
0 路人甲 17
1 路人乙 18
2 路人丙 34
ID为主键
我想得到 ‘路人乙‘
declare @temp=.......
select .......
老宛 2004-08-17
  • 打赏
  • 举报
回复
是不是
id 姓名 年龄
1 路人甲 17
2 666 18
3 qqq 34

id是主键的话,比如找qqq的年龄

select 年龄 from yourtable where [id]=3
skyboy0720 2004-08-17
  • 打赏
  • 举报
回复
你给的数据什么意思?
zhangjidong 2004-08-17
  • 打赏
  • 举报
回复
ID 性名 年龄
路人甲 17
666 18
qqq 34

34,587

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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