mysql sql 问题

yuepengfei 2007-03-09 04:52:01
有两个表a,b
a表结构
testid int(11)
b表结构
b_id int(11)
testid int(11)
status int(2)
note varchar(50)
a表和b表通过testid关联,我需要取出 a表的testid和b表的note,其中根据b表status的不同note分别取别名为note1,note2,……note20,status一共有20个状态,a和b之间的连接可能为inner join 也可能为left join 我现在的sql取法是(以left join为例):
SELECT a.testid,b1.note note1,b2.note note2,b3.note note3,……
FROM a
LEFT JOIN b b1 ON a.testid=b1.testid and b1.status=1
LEFT JOIN b b2 ON a.testid=b2.testid and b2.status=2
LEFT JOIN b b3 ON a.testid=b3.testid and b3.status=3
……
这样写sql比较慢,请问还有别的做法能取出note1,note2,note3……吗?谢谢!
...全文
152 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
zjntche_cn 2007-03-11
  • 打赏
  • 举报
回复
帮回一下吧!^_^
yuepengfei 2007-03-11
  • 打赏
  • 举报
回复
大家帮帮忙呀!
yuepengfei 2007-03-11
  • 打赏
  • 举报
回复
还是自己糊涂了,不是这得问题,解决了,有人回复就揭帖了!
yuepengfei 2007-03-11
  • 打赏
  • 举报
回复
解决了,有人回复就揭帖了!

56,677

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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