简体   繁体   中英

Help with Joining two Tables

I know this has been asked a dozen times here at stackoverflow, but it is driving me mad.

I have two tables:

  1. card_lookup_values (which contains: card_id, card_price )
  2. card_sales (which contains: discount_price )

They both contain card_id (so I know I can join them there), but how exactly would I join them? What I am trying to accomplish is to multiply the card's price it's discount price to get the actual sale price, but it is proving to be a real head scratcher.

SELECT 
  card_lookup_values.card_id,
  card_lookup_values.card_price,
 card_sales.discount_price,
  card_sales.discount_price * card_lookup_values.card_price AS actual_price
FROM card_lookip_values JOIN card_sales ON card_lookup_values.card_id = card_sales.card_id

Or, if your discounts are something like "20% off", the following subtracts the amount discounted (discount * original) from the original to return the new price.

card_lookup_values.card_price - (card_sales.discount_price * card_lookup_values.card_price) AS actual_price
select *
from card_lookup_values clv
left join card_sales cs on clv.card_id = cs.card_id
Select card_price*discount_price from card_lookup_values inner join card_sales
on card_lookup_values.card_id = card_sales.card_id
Select clv.card_price,cs.discount_price card_lookup_values clv inner join card_sales cs on cs.card_id=clv.card_id

编辑选择部分,通过使用正确的别名为ur表cos乘以折扣价Nd到卡价以获得sm号,以进行您自己的计算,这对我来说没有任何意义,因为它不代表任何含义

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