[英]SQL - conditions during query
Basically i want through all the 0's on my database and then start going through the 2's.基本上我想通过我的数据库中的所有 0,然后开始通过 2。
The query is:查询是:
SELECT IP,Time,HostName
FROM RoughScan
CASE WHEN EXISTS (DeepScan=0)
THEN (DeepScan=0 LIMIT 1)
ELSE (DeepScan=2 LIMIT 1)
but i get the error saying:但我收到错误消息:
Unexpected end of CASE expression (near "" at position 0)
CASE 表达式意外结束(位置 0 处的“”附近)
Also i am using MariaDB Server.我也在使用 MariaDB 服务器。
If you want one row of each type, then use union all
:如果您想要每种类型的一行,请使用
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
);
Note that ORDER BY
is usually used with LIMIT
.请注意,
ORDER BY
通常与LIMIT
。
You need to apply CASE to WHERE like this:您需要像这样将 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.