有两张表
Test表                                      Paper表
User Paper                        User Paper   Score
 1     1                            1    1       80
 2     1                            2    1       81
                                    2    1       82
                                    2    2       83
                                    3    1       841、帮我写一条语句,把Paper中的 两个 (2    1       81),   (2    1       82)只保留前一条记录,就是表中如果存在(User,Paper)相同的,只保留第一条记录;
如上表删除后结果为:User Paper   Score
 1    1       80
 2    1       81
 2    2       83
 3    1       842、帮我写一条 Select 语句,结合 Test 与Paper,使Paper中的(User,Paper)与Test中的(User,Paper)相等,但是只能取第一条记录;如上表取的结果是User Paper   Score
1    1       80
2    1       81
                                   
                                                                                                     

解决方案 »

  1.   

    主键我省略了啊。每个表的前面TestID,PaperID是主键,为1,2,3,4,5,。主键没用啊
      

  2.   

    Test表                                      Paper表 
    User Paper                        User Paper  Score 
    1    1                            1    1      80 
    2    1                            2    1      81 
                                        2    1      82 
                                        2    2      83 
                                        3    1      84 2、帮我写一条 Select 语句,结合 Test 与Paper,使Paper中的(User,Paper)与Test中的(User,Paper)相等,但是只能取第一条记录;如上表取的结果是 User Paper  Score 
    1    1      80 
    2    1      81 
                                      
    select [User],[Paper],min([Score]) as [Score]
    from
    (
      select t.[User],t.[Paper],p.[Score]
      from [Test] t
      left join [Paper] p
      on t.[User]=P.[user] and t.[Paper]=p.[Paper]
    ) a
    group by [User],[Paper]
      

  3.   

    谢谢空军。真好,用了Leftjoin,我一直用inner jion老是不行。我待会儿试试看啊先谢谢了我等下结贴呀
      

  4.   

    好啊。。写Delete语句啊呵呵欢迎我是新手,啥也不懂,初来炸到也没多少分数。。只能说声非常感谢!
      

  5.   

    delete from paper,
    (select p1.Paperid,p1.user,p1.Paper,min(p1.Score) as Score
    from paper p1,paper p2 where p1.user=p2.user and p1.paper=p2.paper and p1.paperid<>p2.paperid
    group by [User],[Paper]) as tempPaper where paper.paperid not in (select paperid from tempPaper)
    大概是这样吧。不一定对。