首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >查找MYSQL查询失败的条件(偏差汇总)

问查找MYSQL查询失败的条件(偏差汇总)
EN

Stack Overflow用户
提问于 2019-08-16 17:42:15
回答 2查看 69关注 0票数 1

如果mysql查询条件失败,我需要显示偏差汇总。我需要显示哪个数据输入是错误的,因为我没有得到任何结果。

更多的是合乎逻辑的问题,所以试图用谷歌搜索同样的问题。

表字段: id、日期、日期、时间、节目、标题

查询

代码语言:javascript
复制
SELECT Count(id) FROM `table` 
WHERE day='Monday' and date = '2018-10-15' and time = '19:45:34' and title = 'NEW-BOTTLE'

如果满足all条件,上述查询将返回count。我需要显示偏差汇总,以防任何条件值未得到满足。

例如,如果新瓶子输入为NEW-BOTTLE1,那么我需要显示标题名称是不正确的。

以同样的方式,我需要显示哪个值是错误的,因为发生了哪个计数为0。

EN

回答 2

Stack Overflow用户

发布于 2019-08-16 19:25:01

您可以使用if条件选择值,如下所示:

代码语言:javascript
复制
SELECT IF(day = 'Monday', 'TRUE','FALSE') as dayResult, IF(date = '2018-10-15', 'TRUE','FALSE') as dateResult,
IF(time = '19:45:34', 'TRUE','FALSE') as timeResult, IF(title = 'NEW-BOTTLE', 'TRUE','FALSE') as titleResult   FROM `table` 

它将根据条件满足情况返回1或0。希望它能以任何方式帮助你。

票数 0
EN

Stack Overflow用户

发布于 2019-08-16 21:10:49

您可以使用switch语句打印详细的摘要。下面是伪代码。

代码语言:javascript
复制
switch (true) {

case 0:
    SELECT Count(id) FROM `table`
    WHERE day = 'Monday' and date = '2018-10-15' and time = '19:45:34' and title = 'NEW-BOTTLE'
    // Get the count from query    

    if ($count != '0') {
        // Criteria met successfully, not need to check other cases;
        break;
    }

case 1:
    SELECT Count(id) FROM `table`
    WHERE day = 'Monday' and date = '2018-10-15' and time = '19:45:34'

    //get the count
    if ($count != '0')
        echo "Title is incorrect";

case 2:
    SELECT Count(id) FROM `table`
    WHERE day = 'Monday' and date = '2018-10-15' and title = 'NEW-BOTTLE'
    //get the count
    if ($count != '0')
        echo "Time didn't match";

case 3:
    SELECT Count(id) FROM `table`
    WHERE day = 'Monday' and time = '19:45:34' and title = 'NEW-BOTTLE'
    if ($count != '0')
        echo "Date didn't match";

case 4:
    SELECT Count(id) FROM `table`
    WHERE date = '2018-10-15' and time = '19:45:34' and title = 'NEW-BOTTLE'
    if ($count != '0')
        echo "Day didn't match";
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57522357

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档