I have a problem that i cant solve with a SQL query for MySQL.
First table "content"
ID / Title / Author / Curated / Created
Next table "whitelist"
ID / Author / Weight
What i want the SQL to do is SELECT all content WHERE content.created >= UNIX_TIMESTAMP(DATE_SUB(now(), INTERVAL 14 day))
Also i what to order the Author random of the weight so the author with a high weight will show up more than a lower. As for now i am using this function ORDER BY -LOG(RAND(1337)) / whitelist.weight ASC
. And finally i want every other row to be curated and the next one not.
So the result would be something like this.
ID Title Author Curated Created
3 My Home1 Krister 1 2015-01-20
13 My Home14 Krister 0 2015-01-20
33 My Home8 Eva 1 2015-01-15
34 My Home11 Krister 0 2015-01-01
43 My Home18 Eva 1 2015-01-01
What i have tried...
SELECT *
FROM (
SELECT `content`.*, IF(`content`.`curated`=0, @mr:=@mr+1, @fr:=@fr+1) AS cur
FROM `content` INNER JOIN `whitelist` ON `content`.`author` = `whitelist`.`author` , (SELECT @mr:=0, @fr:=0) initvars
WHERE
content.is_deleted = 0
AND content.created >= UNIX_TIMESTAMP(DATE_SUB(now(), INTERVAL 14 day))
) tmp
INNER JOIN whitelist ON tmp.author = whitelist.author
ORDER BY cur ASC LIMIT 5 OFFSET 0;