急用,跪请高手指教,多给分

sql1 2010-10-25 11:21:19
A表

cxdm lsj
001 2.0
002 5.0
003 7.0

B表
id cxdm
01 001
01 002

想得到C表

id cxdm lsj
01 001 2.0
01 002 5.0

请高手指教?????
...全文
161 27 打赏 收藏 转发到动态 举报
写回复
用AI写文章
27 条回复
切换为时间正序
请发表友善的回复…
发表回复
dawugui 2010-10-26
  • 打赏
  • 举报
回复
create table ta(cxdm varchar(10),lsj varchar(10))
insert into ta values('001','2.0')
insert into ta values('002','5.0')
insert into ta values('003','7.0')
create table tb(id varchar(10),cxdm varchar(10))
insert into tb values('01','001')
insert into tb values('01','002')
go

select tb.* , ta.lsj from tb , ta where tb.cxdm = ta.cxdm

drop table ta , tb

/*
id cxdm lsj
---------- ---------- ----------
01 001 2.0
01 002 5.0

(所影响的行数为 2 行)

*/
abuying 2010-10-26
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 sql1 的回复:]

select tb.id,ta.cxdm,ta.lsj
from ta inner join tb on ta.cxdm=tb.cxdm

结果只有一个值,不是两个值。这个我试过,不行。
[/Quote]
那就试一下
select tb.id,ta.cxdm,ta.lsj
from ta ,tb where ta.cxdm=tb.cxdm

select tb.id,ta.cxdm,ta.lsj
from ta left join tb on ta.cxdm=tb.cxdm
破Feel 2010-10-26
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 shizheyangde 的回复:]
SQL code

create table ta(cxdm varchar(10),lsj varchar(10))
insert into ta values('001','2.0')
insert into ta values('002','5.0')
insert into ta values('003','7.0')
create table tb(id varchar(10……
[/Quote]

可以
破Feel 2010-10-26
  • 打赏
  • 举报
回复
没把握住表现的机会 ……
zhangsuyunpk521 2010-10-26
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 dawugui 的回复:]
SQL code
create table ta(cxdm varchar(10),lsj varchar(10))
insert into ta values('001','2.0')
insert into ta values('002','5.0')
insert into ta values('003','7.0')
create table tb(id varchar(10),……
[/Quote]
+1
Fabulous 2010-10-26
  • 打赏
  • 举报
回复
这个我居然会做
opou 2010-10-26
  • 打赏
  • 举报
回复

create table ta(cxdm varchar(10),lsj varchar(10))
insert into ta values('001','2.0')
insert into ta values('002','5.0')
insert into ta values('003','7.0')
create table tb(id varchar(10),cxdm varchar(10))
insert into tb values('01','001')
insert into tb values('01','002')

select b.id ,a.cxdm,a.lsj from ta a ,tb b where a.cxdm = b.cxdm

---------
id cxdm lsj
01 001 2.0
01 002 5.0
zengjiaqin 2010-10-26
  • 打赏
  • 举报
回复
上面都回答了
alfred_2006 2010-10-26
  • 打赏
  • 举报
回复
呵呵,如果试过,那就是环境有问题了
cloud1215 2010-10-26
  • 打赏
  • 举报
回复
楼上的语句,楼主试试.
fpzgm 2010-10-26
  • 打赏
  • 举报
回复
问题和分数有点。。直接join下。。


create table ta(cxdm varchar(10),lsj varchar(10))
insert into ta values('001','2.0')
insert into ta values('002','5.0')
insert into ta values('003','7.0')
create table tb(id varchar(10),cxdm varchar(10))
insert into tb values('01','001')
insert into tb values('01','002')
go

--方法一
select tb.* , ta.lsj from tb , ta where tb.cxdm = ta.cxdm
--方法二
select tb.*, ta.lsj from tb inner join ta on tb.cxdm = ta.cxdm


drop table ta , tb

/*
id cxdm lsj
---------- ---------- ----------
01 001 2.0
01 002 5.0

(所影响的行数为 2 行)

*/
chuanzhang5687 2010-10-26
  • 打赏
  • 举报
回复
create table A (
cxdm varchar(10),
lsj varchar(10)
)

insert into A values('001','2.0')
insert into A values('002','5.0')
insert into A values('003','7.0')
create table B (
id varchar(10),
cxdm varchar(10)
)
insert into B values('01','001')
insert into B values('01','002')


select b.id,a.cxdm,a.lsj
from a inner join b on a.cxdm=b.cxdm
drop table b
drop table a
fengyun142415 2010-10-26
  • 打赏
  • 举报
回复

select b.id,b.cxdm,a.lsj
from A表 a,B表 b
where a.cxdm=b.cxdm
bourbon1795 2010-10-26
  • 打赏
  • 举报
回复
select B.id,B.cxdm,A.lsj from B left join A on B.cxdm=A.cxdm
zhangbiaoandbill 2010-10-26
  • 打赏
  • 举报
回复
连接查询。。。基础
viqn7qdnt 2010-10-26
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 dawugui 的回复:]
SQL code
create table ta(cxdm varchar(10),lsj varchar(10))
insert into ta values('001','2.0')
insert into ta values('002','5.0')
insert into ta values('003','7.0')
create table tb(id varchar(10),……
[/Quote]

up
wangkun520 2010-10-26
  • 打赏
  • 举报
回复
select b.id,b.cxdm,a.lsj
from A表 a,B表 b
where a.cxdm=b.cxdm

shizheyangde 2010-10-25
  • 打赏
  • 举报
回复
create table ta(cxdm varchar(10),lsj varchar(10))
insert into ta values('001','2.0')
insert into ta values('002','5.0')
insert into ta values('003','7.0')
create table tb(id varchar(10),cxdm varchar(10))
insert into tb values('01','001')
insert into tb values('01','002')

select tb.id,ta.cxdm,ta.lsj
from ta inner join tb on ta.cxdm=tb.cxdm

drop table ta
drop table tb

/**
ID cxdm lsj
----------- -----------
01 001 2.0
01 002 5.0

(2 行受影响)
**/



shizheyangde 2010-10-25
  • 打赏
  • 举报
回复

create table ta(cxdm varchar(10),lsj varchar(10))
insert into ta values('001','2.0')
insert into ta values('002','5.0')
insert into ta values('003','7.0')
create table tb(id varchar(10),cxdm varchar(10))
insert into tb values('01','001')
insert into tb values('01','002')

select tb.id,ta.cxdm,ta.lsj
from ta inner join tb on ta.cxdm=tb.cxdm

drop table ta
drop table tb
天下如山 2010-10-25
  • 打赏
  • 举报
回复

select B.id,B.cxdm,A.lsj from B left join A on B.cxdm=A.cxdm
加载更多回复(4)

34,593

社区成员

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

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