SQL查询没有执行(在哪里)

时间:2017-08-11 17:17:53

标签: mysql sql where-clause

我在执行sql查询时遇到了一些问题。

在我的bd中我有3列(experimentID,applicationID,intent)

我想通过experimentID = 3

获得一些特定的意图

我的查询是:

SELECT experimentID, applicationID, intent 
from intents 
WHERE experimentID = 3 AND intent='android.intent.action.AIRPLANE_MODE' OR intent='android.intent.action.ALL_APPS' OR intent='android.intent.action.ANSWER' OR intent='android.intent.action.APPLICATION_PREFERENCES' OR intent='android.intent.action.APPLICATION_RESTRICTIONS_CHANGED' OR intent='android.intent.action.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE' OR intent='android.intent.action.APP_ERROR' OR intent='android.intent.action.ASSIST' OR intent='android.intent.action.PHONE_STATE' OR intent='android.intent.action.ATTACH_DATA' OR intent='android.intent.ACTION_SCREEN_OFF' OR intent='android.intent.action.BATTERY_CHANGED' OR intent='android.intent.action.BATTERY_CHANGED_ACTION' OR intent='android.intent.action.BATTERY_LOW' OR intent='android.service.wallpaper.WallpaperService' OR intent='android.intent.action.QUICKBOOT_POWERON' OR intent='android.net.conn.CONNECTIVITY_CHANGE' OR intent='android.intent.action.BATTERY_OKAY' OR intent='android.intent.action.START_SMS_SERVICE' OR intent='android.app.action.ACTION_DEVICE_ADMIN_DISABLE_REQUESTED' OR intent='android.intent.action.BOOT_COMPLETED' OR intent='android.intent.action.BUG_REPORT' OR intent='android.intent.action.CALL' OR intent='android.intent.action.RESPOND_VIA_MESSAGE' OR intent='android.intent.action.CALL_BUTTON' OR intent='android.intent.action.CAMERA_BUTTON' OR intent='android.intent.action.CARRIER_SETUP';

问题是我还得到了其他的experimentID ...(不仅是experimentID = 3)

我认为这是因为查询中的OR,但我怎样才能进行查询以获得仅经验ID = 3?问题显然在WHERE

感谢您的帮助!

2 个答案:

答案 0 :(得分:4)

括号可以解决问题。但更好的解决方案是in

SELECT experimentID, applicationID, intent
FROM intents
WHERE experimentID = 3 AND
      intent IN ('android.intent.action.AIRPLANE_MODE', 
                 . . .
                 'android.intent.action.CARRIER_SETUP'
                );

答案 1 :(得分:0)

SELECT experimentID, applicationID, intent 
from intents 
WHERE experimentID = 3 
((AND intent='android.intent.action.AIRPLANE_MODE')( OR intent='android.intent.action.ALL_APPS' OR intent='android.intent.action.ANSWER' OR intent='android.intent.action.APPLICATION_PREFERENCES' OR intent='android.intent.action.APPLICATION_RESTRICTIONS_CHANGED' OR intent='android.intent.action.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE' OR intent='android.intent.action.APP_ERROR' OR intent='android.intent.action.ASSIST' OR intent='android.intent.action.PHONE_STATE' OR intent='android.intent.action.ATTACH_DATA' OR intent='android.intent.ACTION_SCREEN_OFF' OR intent='android.intent.action.BATTERY_CHANGED' OR intent='android.intent.action.BATTERY_CHANGED_ACTION' OR intent='android.intent.action.BATTERY_LOW' OR intent='android.service.wallpaper.WallpaperService' OR intent='android.intent.action.QUICKBOOT_POWERON' OR intent='android.net.conn.CONNECTIVITY_CHANGE' OR intent='android.intent.action.BATTERY_OKAY' OR intent='android.intent.action.START_SMS_SERVICE' OR intent='android.app.action.ACTION_DEVICE_ADMIN_DISABLE_REQUESTED' OR intent='android.intent.action.BOOT_COMPLETED' OR intent='android.intent.action.BUG_REPORT' OR intent='android.intent.action.CALL' OR intent='android.intent.action.RESPOND_VIA_MESSAGE' OR intent='android.intent.action.CALL_BUTTON' OR intent='android.intent.action.CAMERA_BUTTON' OR intent='android.intent.action.CARRIER_SETUP'));