sql查询联接两个表

编程入门 行业动态 更新时间:2024-10-28 19:20:16
本文介绍了sql查询联接两个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

hi .. 我有个问题.请帮我解决. 我有两个表1ST结构是 ID HEAD1 HEAD2 HEAD3 10 3400 500 600 11 6400 800 600 12 8400 500 600 131400900600 ----------------------------- 第二张表 标题说明 HEAD1 AAAAA HEAD2 BBBBB HEAD3 CCCCC HEAD4 DDDDD ------------------------------------------------- 我必须通过其描述来获取价值. AS:--- ID说明AMT 10 AAAAA 3400 10 BBBBB 500 10 CCCCC 600 11 AAAAA 6400 11 BBBBB 800 11 CCCCC 600 12 AAAAA 6400 12 BBBBB 800 12 CCCCC 600 13 AAAAAA 1400 13 BBBBBB 900 13 CCCCCC 600

hi.. I have a problem. please help me in solving it. I HAVE TWO TABLE 1ST STRUCTURE IS ID HEAD1 HEAD2 HEAD3 10 3400 500 600 11 6400 800 600 12 8400 500 600 13 1400 900 600 ----------------------------- 2ND TABLE IS HEADNAME DESCRIPTION HEAD1 AAAAA HEAD2 BBBBB HEAD3 CCCCC HEAD4 DDDDD ------------------------------------------------- I HAVE TO GET VALUE WITH THEIR DESCRIPTION. AS :--- ID DESCRIPTION AMT 10 AAAAA 3400 10 BBBBB 500 10 CCCCC 600 11 AAAAA 6400 11 BBBBB 800 11 CCCCC 600 12 AAAAA 6400 12 BBBBB 800 12 CCCCC 600 13 AAAAAA 1400 13 BBBBBB 900 13 CCCCCC 600

推荐答案

要联接至少一列,在两个表中应该是公用的,但是在您的表中没有公用的列,请告诉我如何获取金额,因为AMT列在任何表中都不存在. For joining at least one column should be common in both table but in your table there is no common column and tell me how can u get amount because AMT column does not exist in any table .

您对数据库的设计不够好 但按照输入输出示例, 您可以使用以下查询, you have not designed database very well but as per input output example, you can use below query, select * from ( select Id,(select Description from table2 where headname='head1') as Description,head1 as amt from table1 union all select Id,(select Description from table2 where headname='head2') as Description,head2 as amt from table1 union all select Id,(select Description from table2 where headname='head3') as Description,head3 as amt from table1 ) as a order by id,Description

祝您编程愉快! :)

Happy coding! :)

更多推荐

sql查询联接两个表

本文发布于:2023-10-19 19:03:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1508475.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:两个   sql

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!