[英]How can I join two SQL tables, putting a value from the 2nd table into a column in the 1st?
I've no idea where to start with this! 我不知道从哪里开始! I have two tables, one which shows a company mobile phone bill in detail, like this: 我有两个表格,一个表格详细显示了公司的手机话费,如下所示:
And another table which shows line rental, like this: 另一个显示线路租金的表格,如下所示:
I want to "merge" the two tables, so that the Line Rental value is shown in the Call Cost column, the value "Line Rental" is shown in the Call Class column, and the Bill Date is shown in the Date column: 我想“合并”这两个表,以使“线路租金”值显示在“呼叫成本”列中,而““线路租金””值显示在“呼叫类别”列中,而“帐单日期”显示在“日期”列中:
Try this 尝试这个
select User,callcost,callclass,date from 1sttable
union all
select User,LineRental,'Line Rental',billdate from 2ndtable
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.