Thanks for your reply. I tried your query, and it worked fine after some few alterings and adjustments.
My query now looks like this:
(SUM and GROUP BY is disabled at the moment, instead it lists every rows for each group)
SELECT
@totdays:=LEAST(TO_DAYS(`til_dato`),TO_DAYS('2003-11-19'))-GREATEST(TO_DAYS(`fra_dato`),TO_DAYS('2003-11-01')) AS totdays,
@startday:=WEEKDAY(GREATEST(`fra_dato`,'2003-11-01')) AS startday,
@days:=@totdays - 2*FLOOR(@totdays/7) - IF(@startday + MOD(@totdays,7) - 4 < 0, 0, LEAST(@startday + MOD(@totdays,7) - 4, 2))
+ IF(@totdays + @startday < 6, 1, 1) As WeekDays, `sortorder`,
@days:=IF(@days>=0,@days,0) AS days,
@days*`belop` AS kost,
`hvor`.`value` AS hvorValue
FROM hvor, media_kost
WHERE `media_kost`.`mId`=`hvor`.`hId`
AND `media_kost`.`dager`=1
AND `hvor`.`active`=1
AND `hId`=13
ORDER BY `sortorder`, hvorValue LIMIT 10;
The problem now is that AND `hId` is required. hId refers to the hvorValue, which will be GROUP'ed BY. If AND hId=13 (or any other id) is there, it works fine. If I remove that line, all `days`-fields returns 1, which isnt right. (hId=13 refers to Altavista.no). Its also not possible to select more hId's, only one will be accepted. I've tried AND (hId=13 OR hId=14, etc) and AND hId IN (13,14,etc).
Here's the result with AND hId=13:
http://sql-servers.com/nopaste/?show=1305
Heres the result without AND hId=13:
http://sql-servers.com/nopaste/?show=1306