亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在MYSQL查詢中查找哪個條件失?。ㄆ顓R總)

在MYSQL查詢中查找哪個條件失?。ㄆ顓R總)

PHP
哈士奇WWW 2021-11-26 15:52:39
如果任何 mysql 查詢條件失敗,我需要顯示偏差摘要。我需要顯示哪些數據輸入錯誤,因為我得到了 NONE 結果。更多的邏輯問題所以試圖用谷歌搜索同樣的問題。表字段:id、day、date、time、program、title詢問SELECT Count(id) FROM `table` WHERE day='Monday' and date = '2018-10-15' and time = '19:45:34' and title = 'NEW-BOTTLE'如果滿足所有條件,上述查詢將返回計數。如果任何條件值不滿意,我需要顯示偏差摘要。例如,如果 NEW-BOTTLE 輸入為 NEW-BOTTLE1,那么我需要顯示標題名稱不正確。以同樣的方式,我需要顯示由于發生了哪個計數 0 而哪個值是錯誤的。
查看完整描述

2 回答

?
米琪卡哇伊

TA貢獻1998條經驗 獲得超6個贊

您可以使用if條件選擇值,如下所示:


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根據條件滿足。希望它以任何方式幫助你。


查看完整回答
反對 回復 2021-11-26
?
白衣非少年

TA貢獻1155條經驗 獲得超0個贊

您可以使用 switch 語句打印詳細摘要。這是偽代碼。


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";

}


查看完整回答
反對 回復 2021-11-26
  • 2 回答
  • 0 關注
  • 172 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號