我们如何加入同一个表本身 [英] How can we Join same table itself
本文介绍了我们如何加入同一个表本身的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一张桌子像
I have a table like
AccID AccType Balance
1 Saving 1-saving-bal
1 Current 1-current-bal
2 Saving 2-saving-bal
2 Current 2-current-bal
3 Saving 3-saving-bal
3 Current 3-current-bal
我想要检索数据,如...
I Want to retrieve the data like..
AccID AccType Balance AccID2Balance
1 Saving 1-saving-bal 2-saving-bal
1 Current 1-current-bal 2-current-bal
如何撰写查询..
请帮助..
How can i write query..
Please help..
推荐答案
我收到了查询..
I got the Query..
SELECT t1.AccID,t1.AccType,t1.Balance,t2.Balance as AccID2Balance
FROM table_name t1 JOIN table_name t2 ON t1.Acctype=t2.AccType
WHERE t1.AccID=1 AND t2.AccID=2
谢谢...... :)
Thank you... :)
这篇关于我们如何加入同一个表本身的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文