在线等,关于返加大类名称,小类名称的sql语句写法

popsn 2007-07-11 01:18:01
我有两个表,
table1:bigclassid,smallclassid 这两个人都是对应table2的主键classid
table2:classid,classname
请问如何写个sql语句得到table1中的分类名称.

...全文
143 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
popsn 2007-07-11
  • 打赏
  • 举报
回复
可惜,这段时间没邹老大出现了.04年时常见老大.
nitjump 2007-07-11
  • 打赏
  • 举报
回复
又见一两清风
popsn 2007-07-11
  • 打赏
  • 举报
回复
我用了一个#table通过中转才能实现.
很感谢楼上两位高手,用一句语句给解决了.
hellowork 2007-07-11
  • 打赏
  • 举报
回复
declare @ta table(bigclassid int,smallclassid int)
declare @tb table(classid int,classname varchar(10))
insert @ta select 1,2
insert @tb
select 1,'a' union all
select 2,'b'

select b.classname,c.classname from @ta as a
left join @tb as b on a.bigclassid = b.classid
left join @tb as c on a.smallclassid = c.classid

/*结果
classname classname
---------- ----------
a b
*/
chuifengde 2007-07-11
  • 打赏
  • 举报
回复
select bigName=(select top 1 classname from table2 where bigclassid=a.classid),
smallName=(select top 1 classname from table2 where smallclassid=a.classid) from table1 a
popsn 2007-07-11
  • 打赏
  • 举报
回复
能不能通过分类表table2,把table1中的两个大类ID,小类ID,变成大类名称,小类名称

34,837

社区成员

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

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