简体   繁体   中英

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM