如何在MYSQl查询中使用条件if-else。 [英] How to use Conditional if-else in MYSQl query.

查看:3264
本文介绍了如何在MYSQl查询中使用条件if-else。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个表(1)tblborrowloan包含列pno,LoanAmt。

(2)tblextraloan包含列pno,LoanAmt。

我需要从表中选择LoanAmt 2根据pno但是如果它返回null则数据应该来自表1,基于相同的pno。

这里是我的qury ..但没有执行,使用Mysql(Ver 5.0)作为后端。

帮助我。在此先感谢。



ifnull(SELECT LoanAmt FROM tblextraloan其中pno ='0706'为L)然后(SELECT LoanAmt FROM tblborrowloan其中pno ='0706'为L) ;

I have two tables (1) tblborrowloan contain columns pno, LoanAmt.
(2) tblextraloan contain columns pno, LoanAmt.
I need to select LoanAmt from table 2 according to pno but if it returns null then data should come from table 1 on the basis of same pno.
here is my qury.. but not executing, using Mysql(Ver 5.0) as backend.
Help me out. Thanks in Advance.

ifnull (SELECT LoanAmt FROM tblextraloan where pno = '0706' as L) then (SELECT LoanAmt FROM tblborrowloan where pno = '0706' as L);

推荐答案

我认为您编写的查询语法根据MYSQL语法不正确。





如果第一个表达式不为null,则返回第一个表达式结果,否则返回第二个表达式。



查询可能是..

I think the query syntax you have written is not correct as per the MYSQL syntax.


If the first expression is not null it returns the first expression result,else the second one.

the query could be..
ifnull((SELECT LoanAmt FROM tblextraloan where pno = '0706' as L),(SELECT LoanAmt FROM tblborrowloan where pno = '0706' as L));





了解更多详情请参阅以下链接。

http: //dev.mysql.com/doc/refman/5.0/en/control-flow-functions.html#function_ifnull [ ^ ]


这篇关于如何在MYSQl查询中使用条件if-else。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆