[英]MySQL,PHP: count results per condition + get the total result that satisfies the conditions
SELECT *,
SUM(CASE WHEN XXX LIKE '999' AND YYY RLIKE '[0-9]8[0-9]' THEN 1 ELSE 0 END) AS Count999,
SUM(CASE WHEN XXX LIKE '111' AND YYY RLIKE '[0-9]2[0-9]' THEN 1 ELSE 0 END) AS Count111
FROM querytest
WHERE
( XXX LIKE '999' AND YYY RLIKE '[0-9]8[0-9]')
OR
( XXX LIKE '111' AND YYY RLIKE '[0-9]2[0-9]')
Array
(
[0] => 999
[xxx] => 999
[1] => 888
[yyy] => 888
[2] => 2
[Count999] => 2
[3] => 1
[Count111] => 1
)
I'm using php.and i want a query that 我正在使用php。并且我想要一个查询
let me know how many results I can get from ( XXX LIKE '999' AND YYY RLIKE '[0-9]88[0-9]') and how many results i can get from ( XXX LIKE '111' AND YYY RLIKE '[0-9]23[0-9]') and so on. 让我知道我可以从(XXX LIKE'999'和YYY RLIKE'[0-9] 88 [0-9]')得到多少结果,我可以从(XXX LIKE'111'和YYY RLIKE '[0-9] 23 [0-9]'),依此类推。 like in the previous query.
就像上一个查询一样。
gets me all the results like if im using this query: 让我获得所有结果,例如im使用此查询:
SELECT * FROM querytest WHERE ( XXX LIKE '999' AND YYY RLIKE '[0-9]8[0-9]') OR ( XXX LIKE '111' AND YYY RLIKE '[0-9]2[0-9]')
how can I combine the two previous points into one query? 如何将前面的两个点合并为一个查询? plus the ability of using LIMIT and ORDER with the second point.
加上第二点使用LIMIT和ORDER的功能。
您或者需要进行单独的查询,或者使用UNION。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.