jimie VIP
Total posts: 531
19 May 2015 17:13

Hello Sergey,

Can you help me with an example of sql query, used to count the number of child articles that a user received for his articles ?

Rgds

Last Modified: 03 Jun 2015

Tags Developer


Sergey
Total posts: 13,748
19 May 2015 18:27

So you are in the parent field and you what to count total of children?

SELECT COUNT(record_id) FROM `#__js_res_record_values` WHERE field_value = '11' AND field_id = '12'

Where 11 is an ID of the parent record and 12 is an ID of the child field.


jimie VIP
Total posts: 531
19 May 2015 18:42

Nope, I want, to count number of all chields that a user has for all his articles


Sergey
Total posts: 13,748
22 May 2015 04:54
SELECT COUNT(v.record_id) 
  FROM `#__js_res_record_values` AS v 
 WHERE v.field_value IN(SELECT id FROM `#__js_res_record` WHERE user_id = 845) 
   AND v.field_id = '12'

jimie VIP
Total posts: 531
22 May 2015 10:33

Thanks we are close :) what about counting only those who are new ?

Rgds


Sergey
Total posts: 13,748
27 May 2015 15:58

How do yu define new? Last 10 days?


jimie VIP
Total posts: 531
27 May 2015 17:23

New, means all those chield records that the user has not viewed/accessed detail page


Sergey
Total posts: 13,748
01 Jun 2015 12:28
SELECT 
    COUNT(v.record_id)
FROM
    `#__js_res_record_values` AS v
WHERE
    v.field_value IN (SELECT 
            id
        FROM
            `#__js_res_record`
        WHERE
            user_id = 845 AND section_id = 1
                AND id NOT IN (SELECT 
                    record_id
                FROM
                    `#__js_res_hits`
                WHERE
                    section_id = 1 AND user_id = 845))
        AND v.field_id = '12'

jimie VIP
Total posts: 531
01 Jun 2015 13:04

Don't work always returns 0, I give up dont want to wait 1 more week for another hint. (I did changeded the ids according to my case)

Rgds


Sergey
Total posts: 13,748
03 Jun 2015 06:54

You have to change all 1 of section_id to section id of children.

SELECT 
    COUNT(v.record_id)
FROM
    `#__js_res_record_values` AS v
WHERE
    v.field_value = 124
AND v.user_id = 845
AND v.record_id NOT IN (
    SELECT 
        h.record_id
    FROM
        `#__js_res_hits` AS h
    WHERE
        h.section_id = 1 AND h.user_id = 845
)

I changed the query. v.field_value = 124 it is an ID of the parent record. You can try to delete AND v.user_id = 845 if you have limitation and users may only add childrent to his own parents.

Powered by Cobalt