Håll i hatten...
Nu skulle jag vilja lista alla kategorier och räkna ihop vad en annan person har röstat på i varje kategori (Antalet röster & snittbetyget), och inte nog med det utan även hur många röster jag har lagt som är lika den andra personens röst.
...Om detta överhuvudtaget går. :)
Databas är Mysql 5.0 så jag kan ju även skapa views och så om det behövs.
Tips till en barskrapad man emottages varmt.
select c.cname
, concat(sum(case when u.uname = 'Pelle' then 1 else 0 end),
'/',
sum(case when u.uname = 'Kalle' then 1 else 0 end))
, concat(sum(case when u.uname = 'Pelle' then v.vrate else 0 end)
/ sum(case when u.uname = 'Pelle' then 1 else 0 end),
'/',
sum(case when u.uname = 'Kalle' then v.vrate else 0 end)
/ sum(case when u.uname = 'Kalle' then 1 else 0 end))
from votes v
inner
join objects o
on o.oid = v.void
inner
join categories c
on c.cid = o.ocat
inner
join users u
on v.vuser = u.uid
where u.uname
in ('Pelle', 'Kalle')
group
by c.cname
order
by c.cname
select c.cname
, sum(case when u.uname = 'Pelle' then 1 else 0 end) as theirs
, sum(case when u.uname = 'Kalle' then 1 else 0 end) as mine
, concat(sum(case when u.uname = 'Pelle' then v.vrate else 0 end)
/ sum(case when u.uname = 'Pelle' then 1 else 0 end),
'/',
sum(case when u.uname = 'Kalle' then v.vrate else 0 end)
/ sum(case when u.uname = 'Kalle' then 1 else 0 end))
from votes v
inner
join objects o
on o.oid = v.void
inner
join categories c
on c.cid = o.ocat
inner
join users u
on v.vuser = u.uid
where u.uname
in ('Pelle', 'Kalle')
group
by c.cname
having sum(case when u.uname = 'Pelle' then 1 else 0 end) > 0
and sum(case when u.uname = 'Kalle' then 1 else 0 end) > 0
order
by c.cname
select c.cname
, sum(case when u.uname = 'Pelle' then 1 else 0 end) as theirs
, sum(case when u.uname = 'Kalle' then 1 else 0 end) as mine
, concat(sum(case when u.uname = 'Pelle' and v.void in (select void from votes inner join users on vuser = uid where uname = 'Kalle') then v.vrate else 0 end)
/ sum(case when u.uname = 'Pelle' and v.void in (select void from votes inner join users on vuser = uid where uname = 'Kalle') then 1 else 0 end),
'/',
sum(case when u.uname = 'Kalle' and v.void in (select void from votes inner join users on vuser = uid where uname = 'Pelle') then v.vrate else 0 end)
/ sum(case when u.uname = 'Kalle' and v.void in (select void from votes inner join users on vuser = uid where uname = 'Pelle') then 1 else 0 end))
from votes v
inner
join objects o
on o.oid = v.void
inner
join categories c
on c.cid = o.ocat
inner
join users u
on v.vuser = u.uid
where u.uname
in ('Pelle', 'Kalle')
group
by c.cname
having sum(case when u.uname = 'Pelle' then 1 else 0 end) > 0
and sum(case when u.uname = 'Kalle' then 1 else 0 end) > 0
order
by c.cname
select c.cname
, sum(case when u.uname = 'Kalle' then 1 else 0 end) as Ours
, concat(sum(case when u.uname = 'Pelle' then v.vrate else 0 end)
/ sum(case when u.uname = 'Pelle' then 1 else 0 end),
'/',
sum(case when u.uname = 'Kalle' then v.vrate else 0 end)
/ sum(case when u.uname = 'Kalle' then 1 else 0 end))
from votes v
inner
join objects o
on o.oid = v.void
inner
join categories c
on c.cid = o.ocat
inner
join users u
on v.vuser = u.uid
where u.uname
in ('Pelle', 'Kalle')
and o.Id in(SELECT v2.oid FROM votes v2 WHERE v2.uname IN ('Kalle', 'Pelle') GROUP BY v2.id HAVING COUNT(v2.oid) = 2)
group
by c.cname
order
by c.cname
259 ms totalt · 4 externa anrop · v20260731065814-full.1dc6f849