功能描述:用户从节目列表里选出6个节目填入活动前六名,有排名顺序。
举例:用户选择的节目id为211,233,245,25,21,10(按排名顺序)
请大家给个建议,表结构设计应该设计成什么样的,统计的时候会根据用户提交的六个节目与结果进行比对
4个相符
5个相符
6个相符
6个相符,且次序相符字段:
id 记录id
userid 用户id
votedate 投票日期
first 第一名
second 第二名
third 第三名
forth 第四名
fifth
sexth
字段:
id 记录id
userid 用户id
votedate 投票日期
order 名次
actid 节目id

解决方案 »

  1.   

    一个表即可 
    id   记录id 
    userid   用户id 
    votedate   投票日期 
    val 数量
    px  名次
    actid   节目id
    --这样即可.
      

  2.   

    3表
    用户表
    节目表
    投票表(id,节目id,用户id,名次)
      

  3.   

    如果就用第一种方式,结果为221,220,219,218,217,216,
    统计的sql语句需要怎么写呢?
    0001   ,   221,220,219,218,217,216 //特等奖
    0002   ,   221,220,219,218,215,214 //三等奖
    0003   ,   221,220,219,218,217,215 //二等奖
    0004   ,   221,220,219,218,217,214 //
    0005   ,   220,221,219,218,217,216
    0006   ,   221,220,219,212,211,210
      

  4.   

    --表设计,只给出关键表,其它表自己定义.
    --节目名次结果表,记录前六名的节目
    declare @jm table(名次 int,节目id int)
    --投票记录表,每个用户的投票记录最多为6条
    declare @tp table(用户id int,名次 int,节目id int)--统计名次
    select 用户,
    case  when
          (select count(*) from @jm a,@tp b 
           where b.用户 = c.用户 and a.名次 = b.名次 and a.节目id = b.节目id) = 6
          then '6个相符,且次序完全相符'
    else
      case (select count(*) from @tp where 用户 = c.用户 and 节目id in(select 节目id from @jm)) 
        when 6 then '6个相符'
        when 5 then '5个相符'
        when 4 then '4个相符'
      else  then '其它'
      end
    end
    from @tp 
    group by 用户