简体   繁体   English

如何连接两个SQL表,将第二个表中的值放入第一个表中的列?

[英]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.

相关问题 SQL连接2个表,从第2个条件查询第1个表 - SQL join 2 tables, query 1st with condition from 2nd 如何联接两个表,其中第二个表中不得包含第一个表中的ID,但它们是关键 - How to join two tables where IDs from 1st one mustn't be included in 2nd one but they're the key 如果第 2 个表中存在第 1 个表的值,则用第 1 个和第 2 个表的总和更新第 2 个表的值,否则将第一个表数据插入到第 2 个表 - If value of 1 table exists in the 2nd table, update the 2nd table value with sum of 1st and 2nd tables, else insert 1st table data to 2nd table SQL ORDER BY 第一列,但如果第一列为空,则用第二列中的值替换空值 - SQL ORDER BY 1st column, but if 1st column is empty replace the empty value by a value from 2nd column 如何从2个表中删除mysql记录,但是如果第2个表中没有记录仍从第1个表中删除呢? - How do I delete mysql records from 2 tables, but if no records in 2nd table still delete from 1st table? 从 SQL Server 表中的带连字符的字符串列中提取第 1 个第 2 个第 3 个值直到第 n 个值 - Extract 1st 2nd 3rd values till nth value from hyphenated string column in SQL Server table 想要查询连接第一个表的第一行和第二个表的前两列 - want query to connect 1st table 1st row and 2nd table first two column 在 sql 中查找运行总计 - 如果第一列没有值,则从第二列计算 - Find Running Total In sql - if 1st column has no value then calculate from 2nd column 如何在另一个表中选择具有相同值的SQL表中的第一行和第二行实例? - How to select 1st and 2nd row instance in SQL table having the same value in another table? Mysql - 如何根据第一个表的 2 列的值显示第二个表中的列? - Mysql - How to display column from 2nd table based on values from 2 columns of 1st table?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM