// CODE1 (Mysql (MariaDB 10.8.3) query):
SELECT s.`p_p`, COUNT(REGEXP_SUBSTR(r.`xml`, '[0-9]+'))
FROM `#__s` AS s, `#__p` AS x, `#__v` AS r
WHERE REGEXP_SUBSTR(r.`xml`, '[0-9]+') = [user_id] AND s.`user_id` = r.`user` AND x.`id` = s.`p_p`
GROUP BY REGEXP_SUBSTR(r.`xml`, '[0-9]+'), s.`p_p`
ORDER BY FIELD(x.`id`, 44, 14, 11, 10, 18, 4)
// Note1: works fine
// CODE2 (phpMyAdmin (5.2.0) query convertion to PHP (7.4.30)):
$query = "SELECT s.`p_p`, COUNT(REGEXP_SUBSTR(r.`xml`, \'[0-9]+\'))
FROM `#__s` AS s, `#__p` AS x, `#__v` AS r
WHERE REGEXP_SUBSTR(r.`xml`, \'[0-9]+\') = [user_id] AND s.`user_id` = r.`user` AND x.`id` = s.`p_p`
GROUP BY REGEXP_SUBSTR(r.`xml`, \'[0-9]+\'), s.`p_p`
ORDER BY FIELD(x.`id`, 44, 14, 11, 10, 18, 4);";
// Note2: Having phpMyAdmin to convert CODE1 to php it gives CODE2. Only \ was added and made it not to work. Taking \ out, works just fine as it is exactly the same as CODE1 which also works.
// CODE3 (PHP (7.4.30) query in Joomla (3.10.11) syntax):
$query = $db
->getQuery(true)
->select($db->quoteName('s.p_p'), $db->quoteName('COUNT(REGEXP_SUBSTR(r.`xml`, \'[0-9]+\'))'))
->from($db->quoteName('#__s', 's'), $db->quoteName('#__p', 'x'), $db->quoteName('#__v', 'r'))
->where($db->quoteName('(REGEXP_SUBSTR(r.`xml`, \'[0-9]+\'))') .' = [user_id]' AND $db->quoteName('s.user_id') .' = '. $db->quoteName('r.user') AND $db->quoteName('x.id') .' = '. $db->quoteName('s.p_p'))
->group($db->quoteName('(REGEXP_SUBSTR(r.`xml`, \'[0-9]+\'))'), $db->quoteName('s.p_p'));
// Note3: In an effort to convert CODE1 to Joomla syntax, I can't make it work (even without the \). Using try/catch throws an error in line ->group. I also need to add the ORDER BY FIELD(x.`id`, 44, 14, 11, 10, 18, 4) but I don't know how.