SQL-查询期间的条件

时间:2019-02-01 12:16:10

标签: mysql sql

基本上我想遍历数据库中的所有0,然后再开始遍历2。

查询为:

   SELECT IP,Time,HostName
     FROM RoughScan
CASE WHEN EXISTS (DeepScan=0) 
     THEN (DeepScan=0 LIMIT 1) 
     ELSE (DeepScan=2 LIMIT 1)

但我收到错误消息:

  

CASE表达式的意外结尾(位置“ 0”附近的“”附近)

我也在使用MariaDB服务器。

2 个答案:

答案 0 :(得分:0)

如果每种类型都需要一行,请使用window.CKEDITOR.on('dialogDefinition', function (ev) { var dialogName = ev.data.name; var dialogDefinition = ev.data.definition; ev.editor.getCommand( 'table' ).allowedContent = "table{width,height}[align,border,cellpadding,cellspacing,summary];caption tbody thead tfoot;th td tr;table[id,dir](*){*}"; if (dialogName == "table" && dialogName == "tableProperties") { var infoTab = dialogDefinition.getContents("info"); infoTab.get("txtWidth")["default"] = ""; infoTab.get("txtCellSpace")["default"] = ""; infoTab.get("txtCellPad")["default"] = ""; infoTab.get("txtBorder")["default"] = ""; infoTab.get("selHeaders")["items"].pop(); infoTab.get("selHeaders")["items"].pop(); var advancedTab = dialogDefinition.getContents( 'advanced' ); advancedTab.remove( 'advCSSClasses' ); } });

union all

请注意,(SELECT `IP`,`Time`,`HostName` FROM `RoughScan` WHERE DeepScan = 0 LIMIT 1 ) UNION ALL (SELECT `IP`,`Time`,`HostName` FROM `RoughScan` WHERE DeepScan = 2 LIMIT 1 ); 通常与ORDER BY一起使用。

答案 1 :(得分:0)

您需要像这样将CASE应用于WHERE:

SELECT IP,Time,HostName
FROM RoughScan
WHERE 
  DeepScan = CASE 
    WHEN EXISTS (SELECT 1 FROM RoughScan WHERE DeepScan = 0) THEN 0 
    ELSE 2 
  END
LIMIT 1