nid type title created
10 provider test one 1298107010
11 provider test two 1298107555
12 provider example one 1300524695
13 provider example two 1298081391
14 provider example three 1298082340
15 company example four 1298083519
16.... company example five 1298083559
1, the value of nid is equals the value of content_id in table 2.
the title list queue order is:
1, first according to table 2 content_id descending the tile list(decending content_id using “For each content_id, the number of rows with value=1 minus the number of rows with value=0” )
2, because table2 maybe less than 22 records and has the same value when the number of rows with value=1 minus the number of rows with value=0. when emerge this condition. using the created field in table 1 to descending the tile
this is as close as i got to understanding your very weird requirements –
SELECT 1 AS seq
, content_id AS nid
, COUNT(CASE WHEN value = 1
THEN 0 ELSE NULL END) -
COUNT(CASE WHEN value = 0
THEN 1 ELSE NULL END) AS sort_value
FROM votingapi_vote
UNION ALL
SELECT 2 AS seq
, nid
, created AS sort_value
FROM node
WHERE type = 'provider'
ORDER
BY seq
, id DESC
, sort_value DESC LIMIT 22
output the content_id field and descending it, the rule is according to the value(the count of each content_id 's value=1 minus the count of each content_id 's value=0 ,each content_id has many value=0 or value=1). where value_type=option.
namely:For each content_id, the number of rows with value=1 minus the number of rows with value=0
SELECT content_id
, COUNT(CASE WHEN value = 1
THEN 0 ELSE NULL END) -
COUNT(CASE WHEN value = 0
THEN 1 ELSE NULL END) AS diff
FROM votingapi_vote
GROUP
BY content_id