请教关于联赛的积分统计问题 I'll give you answer tonight If you can wait. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 I'll give you score tomorrow If I satisfy. 如果你的赛程安排表中记录数不多,完全不需要积分榜表,因为可以写一个view来计算。如果你用想要建积分榜表,update的时候很麻烦,要通过trigger来完成。以下的方案供你参考:表:赛程安排(轮次,主队,客队,主队得分,客队得分)Table: agenda(round_no, team1, team2, score1, score2)生成view(ORACLE PL/SQL格式):select rownum rank, team, win_games, draw_games, loss_games, total_score, total_loss, total_point from ( select team, sum(win_game) win_games, sum(draw_game) draw_games, sum(loss_game) loss_games, sum(score) total_score, sum(loss) total_loss, sum(point) total_point from ( select team1 team, decode(sign(score1 - score2), 1, 1, 0) win_game, -- 胜 decode(sign(score1 - score2), 0, 1, 0) draw_game, -- 平 decode(sign(score1 - score2),-1, 1, 0) loss_game, -- 负 score1 score, -- 进球 score2 loss, -- 失球 decode(sign(score1 - score2), 1, 3, -- 胜积3分 0, 1, -- 平积1分 0) point, -- 负积0分 from agenda uion all select team2 team, decode(sign(score2 - score1), 1, 1, 0) win_game, -- 胜 decode(sign(score2 - score1), 0, 1, 0) draw_game, -- 平 decode(sign(score2 - score1),-1, 1, 0) loss_game, -- 负 score2 score, -- 进球 score1 loss, -- 失球 decode(sign(score2 - score1), 1, 3, -- 胜积3分 0, 1, -- 平积1分 0) point, -- 负积0分 from agenda ) group by team ) order by total_point, (total_score - total_loss), total_score祝你好运! decode一句没看懂,能不能解释一下decode的用法 decode(expr, para1, value1, para2, value2, ... value_default)get exprif expr = para1 then decode() = value1else if expr = para2 then decode = value2else....else decode() = value_defaultend ifcan you understand? 如果你的數據庫是SQL Server,那麼將decode(...)換成case when ... then ... else ... end agree with zhuzhichao(竹之草), and I think IIF(expr, true_value, flase_value) can also do this. depends on what database you're using. 在select的from中可以在用select嵌套吗?我这边不好用 I don't know, if your database can't use union. but if you can use union, you can create views regarding on all the sub-queries. for example:create 1 view, as select team1 team, decode(sign(score1 - score2), 1, 1, 0? win_game, -- ? decode(sign(score1 - score2), 0, 1, 0? draw_game, -- ? decode(sign(score1 - score2),-1, 1, 0? loss_game, -- ? score1 score, -- ?? score2 loss, -- ?? decode(sign(score1 - score2), 1, 3, -- ??3? 0, 1, -- ??1? 0) point, -- ??0? from agenda uion all select team2 team, decode(sign(score2 - score1), 1, 1, 0? win_game, -- ? decode(sign(score2 - score1), 0, 1, 0? draw_game, -- ? decode(sign(score2 - score1),-1, 1, 0? loss_game, -- ? score2 score, -- ?? score1 loss, -- ?? decode(sign(score2 - score1), 1, 3, -- ??3? 0, 1, -- ??1? 0) point, -- ??0? from agendasave it, let's say 'v_score_detail'.then you can select ... from v_scroe_detailgood luck! 求一个更新的sql语句 在线等一SQL语句 请问函数如何调用存储过程并得到存储过程的输出返回值作为函数的返回值 真搞不明白,这个存储过程为什么没有返回值?? SQL 死锁 问题 救命啊。。 急。。急。。急。。。 关于外关键字约束的问题,帮帮忙 如果商品启用序列号管理数据库设计如何实现? 为了在没有安装Access2K或者只是安装了Access97的机器能够访问Access2K的DB,应该如何? 高高手请进:连接管理员异动错误?? oracle的表分区能够动态生成,删除吗? 如何建立与SQL Server的数据源的连接???
如果你用想要建积分榜表,update的时候很麻烦,要通过trigger来完成。以下的方案供你参考:
表:赛程安排(轮次,主队,客队,主队得分,客队得分)
Table: agenda(round_no, team1, team2, score1, score2)生成view(ORACLE PL/SQL格式):
select rownum rank,
team,
win_games, draw_games, loss_games,
total_score, total_loss, total_point
from (
select team,
sum(win_game) win_games,
sum(draw_game) draw_games,
sum(loss_game) loss_games,
sum(score) total_score,
sum(loss) total_loss,
sum(point) total_point
from (
select team1 team,
decode(sign(score1 - score2), 1, 1, 0) win_game, -- 胜
decode(sign(score1 - score2), 0, 1, 0) draw_game, -- 平
decode(sign(score1 - score2),-1, 1, 0) loss_game, -- 负
score1 score, -- 进球
score2 loss, -- 失球
decode(sign(score1 - score2), 1, 3, -- 胜积3分
0, 1, -- 平积1分
0) point, -- 负积0分
from agenda
uion all
select team2 team,
decode(sign(score2 - score1), 1, 1, 0) win_game, -- 胜
decode(sign(score2 - score1), 0, 1, 0) draw_game, -- 平
decode(sign(score2 - score1),-1, 1, 0) loss_game, -- 负
score2 score, -- 进球
score1 loss, -- 失球
decode(sign(score2 - score1), 1, 3, -- 胜积3分
0, 1, -- 平积1分
0) point, -- 负积0分 from agenda
)
group by team
)
order by total_point, (total_score - total_loss), total_score祝你好运!
para2, value2,
...
value_default)get expr
if expr = para1 then
decode() = value1
else if expr = para2 then
decode = value2
else....else
decode() = value_default
end ifcan you understand?
那麼將decode(...)換成case when ... then ... else ... end
create 1 view, as
select team1 team,
decode(sign(score1 - score2), 1, 1, 0? win_game, -- ?
decode(sign(score1 - score2), 0, 1, 0? draw_game, -- ?
decode(sign(score1 - score2),-1, 1, 0? loss_game, -- ?
score1 score, -- ??
score2 loss, -- ??
decode(sign(score1 - score2), 1, 3, -- ??3?
0, 1, -- ??1?
0) point, -- ??0?
from agenda
uion all
select team2 team,
decode(sign(score2 - score1), 1, 1, 0? win_game, -- ?
decode(sign(score2 - score1), 0, 1, 0? draw_game, -- ?
decode(sign(score2 - score1),-1, 1, 0? loss_game, -- ?
score2 score, -- ??
score1 loss, -- ??
decode(sign(score2 - score1), 1, 3, -- ??3?
0, 1, -- ??1?
0) point, -- ??0?
from agendasave it, let's say 'v_score_detail'.
then you can select ... from v_scroe_detailgood luck!