首页 新闻 论坛 群组 Blog 文档 下载 读书 Tag 网摘 搜索 .NET Java 游戏 视频 人才 外包 培训 数据库 书店 程序员
中国软件网
欢迎您:游客 | 登录 注册 帮助
  • 求一个存储过程 !!高手帮帮忙!! [已结贴,结贴人:sunny044]
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-05-11 19:03:40 楼主
    u_near表
    user near1 near2 ... near20 (21列全是int型)
    u1_base表
    userid itemid rating (3列全是int型)
    我现在已知u_near表中的user值 选择出 near1...near5 这五个分别作为u1_base表中的 userid 还已知itemid 
    然后对应出u1_base表 的5个值(有可能为空)
    现在要得到rating的平均值并返回!!请大家帮帮忙!!

    80  修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • zzyyc
    • 等级:
    发表于:2008-05-11 19:10:341楼 得分:2
    看不懂。
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-05-14 22:24:092楼 得分:2
    引用 1 楼 zzyyc 的回复:
    看不懂。

    同感
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-05-14 22:24:443楼 得分:3
    11号的贴
    我给顶到14号来了
    哈哈
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-05-14 22:25:544楼 得分:3
    写出完整的表结构,然后给点数据,
    给出你要的结果,
    你的叙述貌似看不懂.
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-05-14 22:29:595楼 得分:27
    SQL code
    select [user], avg(rating) as [avg] from (select a.[user],b.rating from u_near a join u1_base b on a.near1=b.userid and b.itemid='?' union all select a.[user],b.rating from u_near a join u1_base b on a.near2=b.userid and b.itemid='?' union all select a.[user],b.rating from u_near a join u1_base b on a.near3=b.userid and b.itemid='?' union all select a.[user],b.rating from u_near a join u1_base b on a.near4=b.userid and b.itemid='?' union all select a.[user],b.rating from u_near a join u1_base b on a.near5=b.userid and b.itemid='?' )T group by [user]
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-05-14 22:36:376楼 得分:27
    SQL code
    --> 已知u_near表中的user值 declare @user int set @user=??? --> 还已知itemid declare @itemid int set @itemid=??? --> 要得到rating的平均值并返回 select avg(rating) from u1_base where itemid=@itemid and userid in ( --> 选择出 near1...near5 这五个分别作为u1_base表中的 userid select near1 from u_near where [user]=@user union all select near2 from u_near where [user]=@user union all select near3 from u_near where [user]=@user union all select near4 from u_near where [user]=@user union all select near5 from u_near where [user]=@user )
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-05-14 22:38:087楼 得分:0
    要抽丝剥茧式的去理解,其实不难,呵呵。
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-05-15 06:13:518楼 得分:10
    引用 6 楼 Limpire 的回复:
    SQL code--> 已知u_near表中的user值declare@userintset@user=???--> 还已知itemiddeclare@itemidintset@itemid=???--> 要得到rating的平均值并返回selectavg(rating)fromu1_basewhereitemid=@itemidanduseridin(--> 选择出 near1...near5 这五个分别作为u1_base表中的 useridselectnear1fromu_nearwhere[user]=@userunionallselectnear2fromu_nearwhere[user]=@userunionallselectnear3fromu_nearwhere[user]=@userunionallsele…
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-05-15 22:35:339楼 得分:2
    学习。
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-05-16 00:00:5310楼 得分:4
    null如何处理,比如有4个数字,1个null,是当作0处理,除数为5还是过滤掉,除数为4?
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-05-16 10:55:4811楼 得分:0
    谢谢大家的帮助 和支持!!!!!
    我已经弄好了!!!
    修改 删除 举报 引用 回复

    网站简介广告服务网站地图帮助联系方式诚聘英才English 问题报告
    世纪乐知(北京)网络技术有限公司 版权所有 京 ICP 证 020026 号
    Copyright © 2000-2007, CSDN.NET, All Rights Reserved