2张表关联的数据怎么提出数据出来

nply2008 2010-03-24 11:39:41
A表
id user_no product_tc statu
1 2 ab 1
2 2 cd 1
3 3 ab 2
4 3 cd 2
5 2 el 1

B表
id product_tc price
1 ab 50
2 cd 20
3 el 35

我要得到结果是:
id user_no product_tc statu price
1 2 ab 1 50
2 2 cd 1 20
3 3 ab 2 50
4 3 cd 2 20
5 2 el 1 35

急啊,昨天一晚上没有睡还没有想出来,下面就没有办法继续做了,晕。


...全文
100 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
ws_hgo 2010-03-24
  • 打赏
  • 举报
回复
select a.id,a.user_no,a.product_tc,b.statu price
from a,b
where a.product_tc = b.product_tc
dawugui 2010-03-24
  • 打赏
  • 举报
回复
select a.* , b.price from a , b where a.product_tc = b.product_tc
fwacky 2010-03-24
  • 打赏
  • 举报
回复

select A.*,B.price
from A left join B on A.product_tc =B.product_tc

东那个升 2010-03-24
  • 打赏
  • 举报
回复
select a.*,b.price from  a ,b  where a.product_tc= b.product_tc 
--小F-- 2010-03-24
  • 打赏
  • 举报
回复
select
a.*,b.price
from
a left join b
on
a.id=b.id
Mr_Nice 2010-03-24
  • 打赏
  • 举报
回复
select A.* ,B.price
from A
left join B on A.product_tc = B.product_tc


看起来好象是这样!
昵称被占用了 2010-03-24
  • 打赏
  • 举报
回复
select a.id,a.user_no,a.product_tc,b.statu price
from a,b
where a.product_tc = b.product_tc
fwacky 2010-03-24
  • 打赏
  • 举报
回复
left join
ChinaJiaBing 2010-03-24
  • 打赏
  • 举报
回复

----try

declare @A table (id int,user_no int,product_tc nvarchar(10),statu int)
insert into @A select 1,2,'ab',1
union all select 2,2,'cd',1
union all select 3,3,'ab',2
union all select 4,3,'cd',2
union all select 5,2,'el',1
declare @B table (id int,product_tc nvarchar(10),price int)
insert into @B select 1,'ab',50
union all select 2,'cd',20
union all select 3,'el',35
select a.id,a.user_no,a.product_tc,a.statu,b.price from @A a join @B b
on a.product_tc=b.product_tc

22,210

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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