日期:2014-05-17 浏览次数:21088 次
select a.id ,(user_id,case
when score>3 then 5
else 3
end as times ,record
from a,(select b.user_id,score,max(xf_time)as last_time ,record from b ,c
where b.user_id = c.user_id
group by b.user_id,score,record) f
where a.end_time<f.last_time
--楼主在加上详细的条件
------解决方案--------------------
select a.id ,user_id,case
when score>3 then 5
else 3
end as times ,record
from a,(select b.user_id,score,max(xf_time)as last_time ,record from b ,c
where b.user_id = c.user_id
group by b.user_id,score,record) f
where a.end_time<f.last_time
--楼主在加上详细的条件
------解决方案--------------------
select b.user_id,
case
when max(b.score) > 3 then
5
else
3
end 可抽注数,
count(c.user_id) 已抽注数
from b,c
where b.user_id = c.user_id(+)
group by b.user_id
不知道楼主想查出ID字段的意义是什么,若说是最近的但是抽奖活动记录表中没得时间字段,仅给出部分代码以供参考
感觉表的设计结构有所累赘
------解决方案--------------------
上面的语句还有点问题,更新如下:
select b.user_id,
case
when max(b.score) > 3 then
5
else
3
end 可抽注数,
case
when (select count(c.user_id)
from c
where user_id = b.user_id
group by user_id) is null then
0
else
(select count(c.user_id)
from c
where user_id = b.user_id
group by user_id)
end 已抽注数
from b, c
where b.user_id = c.user_id(+)
group by b.user_id
继续跟踪,发现有问题或更好的方法请指教
------解决方案--------------------