Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
mysql根据特定条件验证数据的条件_Mysql_Sql - Fatal编程技术网

mysql根据特定条件验证数据的条件

mysql根据特定条件验证数据的条件,mysql,sql,Mysql,Sql,我有两张表,即预订和分类账 预订表格: BookingID -- RegularPrice -- DownPayment -- PerMonthInstallment 1 100,000 10,000 7,500 BookingID Voucher -- PaymentType -- Amount 1 1 Down Payment 10,000 1 2

我有两张表,即
预订
分类账

预订
表格:

BookingID -- RegularPrice -- DownPayment  -- PerMonthInstallment
   1            100,000         10,000          7,500  
BookingID  Voucher  -- PaymentType  -- Amount
1             1        Down Payment    10,000
1             2        Installment     7,500 
分类账
表格:

BookingID -- RegularPrice -- DownPayment  -- PerMonthInstallment
   1            100,000         10,000          7,500  
BookingID  Voucher  -- PaymentType  -- Amount
1             1        Down Payment    10,000
1             2        Installment     7,500 
电流输出为

PaymentType --  PerMonthInstallment -- PaidAmount
Down Payment        7,500                 7,500
Installment#1       7,500                 7,500 
我想要的是,如果
PaymentType
是首付,那么在
permonth分期付款
列中,值应该是
10000
而不是
7500

PaymentType --    PermonthInstallment --    PaidAmount
Down Payment        10,000                   10,000
Installment#1       7,500                     7,500 
我的问题是:

SELECT booking.BookingID,  
       booking.PerMonthInstallment, 
       ledger.PaymentType,
       ledger.PaidAmount,
       ledger.Voucher
from booking
INNER JOIN ledger ON booking.BookingID = ledger.BookingID

好吧,我的第一个建议是,你不应该使用付款类型的词语。你能做的是,你可以给出一个数字作为例子 首付款=1 分期付款=2 所以当你使用它们的时候,你可以把它们的条件 对于您的查询问题,您可以使用

SELECT IF(PaymentType=='Down Payment',10000,7500) AS Dueamount FROM TableName;
如果你改变主意接受我的建议

   SELECT IF(PaymentType==1,10000,7500) AS Dueamount FROM TableName;

原因是假设某个地方会有额外的空间,但考虑到这些空间,你看不到它仍然在编程。需要一些时间才能注意到这个空间,所以用数字代替这个,这是数据库异常,令人困惑。在您的描述中,您谈到了列
dueamunit
,但这样的列既不在示例中,也不在查询中。而不是使用值(750010000)来描述逻辑,这为(错误)解释留下了更多的空间。你应该详细说明。