Index: openacs-4/packages/adserver/tcl/adserver-procs-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/adserver/tcl/adserver-procs-postgresql.xql,v diff -u -r1.2 -r1.2.4.1 --- openacs-4/packages/adserver/tcl/adserver-procs-postgresql.xql 6 Nov 2003 17:26:55 -0000 1.2 +++ openacs-4/packages/adserver/tcl/adserver-procs-postgresql.xql 23 Dec 2004 07:07:19 -0000 1.2.4.1 @@ -54,24 +54,34 @@ - select map.adv_key, track_clickthru_p, target_url, display_count - from adv_group_map map, advs_todays_log log, advs - where group_key = :group_key - and map.adv_key = advs.adv_key - and map.adv_key = log.adv_key - UNION + select + map.adv_key, track_clickthru_p, target_url, display_count + from + adv_group_map map, adv_log log , advs + where + group_key = :group_key + and map.adv_key = advs.adv_key + and map.adv_key = log.adv_key + and log.entry_date=now()::date - select map.adv_key, track_clickthru_p, target_url, 0 as display_count - from adv_group_map map, advs - where group_key = :group_key - and map.adv_key = advs.adv_key - and (select count(*) from adv_log where advs.adv_key=adv_log.adv_key)=0 + UNION - order by display_count asc + select + map.adv_key, track_clickthru_p, target_url, + case when + display_count is null then 0 else display_count end as display_count + from + adv_group_map map, advs + left join adv_log on (advs.adv_key=adv_log.adv_key and adv_log.entry_date=now()::date) + where + group_key = :group_key + and map.adv_key = advs.adv_key - limit 1 + order by display_count asc + limit 1 +