繁体   English   中英

连接两个表的帮助

[英]Help with Joining two Tables

我知道这里在stackoverflow上已经被问过十几遍了,但这让我发疯了。

我有两个表:

  1. card_lookup_values(包含: card_id, card_price
  2. card_sales(包含: discount_price

它们都包含card_id (所以我知道我可以在那里加入它们),但是我将如何加入它们呢? 我要完成的工作是将卡的价格乘以折扣价来获得实际的销售价格,但事实证明,这是一个真正的难题。

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

或者,如果您的折扣类似于“ 20%折扣”,则以下内容将从原始折扣中减去折扣金额(折扣*原始折扣)以返回新价格。

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号,以进行您自己的计算,这对我来说没有任何意义,因为它不代表任何含义

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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