期数         开奖号码 
no(字段名)   a1(字段名) 
1           10 
2           4 
3           1 
4           4 
5           4 
6           1 
7           1 
8           5 
9           5 
10          1 
11          4 
12          2 
13          8 
14          3 
15          4 
16         11 
17          5 
18          5 要求显示如下:a1    no 
1     10 
2     12 
3     14
4     15 
5     18 
8     13 
10    1 
11    16 

解决方案 »

  1.   

    期数         开奖号码 
    no(字段名)   a1(字段名) 
    1           10 
    2           4 
    3           1 
    4           4 
    5           4 
    6           1 
    7           1 
    8           5 
    9           5 
    10          1 
    11          4 
    12          2 
    13          8 
    14          3 
    15          4 
    16         11 
    17          5 
    18          5 要求显示如下:a1    no 
    1     10 
    2     12 
    3     14
    4     15 
    5     18 
    8     13 
    10    1 
    11    16 
      

  2.   

    查开奖号码(不重复)的最后一次no,但要显示所有开过的号码.如5开过4次,只要查出最后一次的no ,第18期.
      

  3.   

    select a1,no from tb a where 
    not exists
    (select 1 from tb where no=a.no and a1>a.a1)
      

  4.   

    DECLARE @TB TABLE([no] INT, [a1] INT)
    INSERT @TB 
    SELECT 1, 10 UNION ALL 
    SELECT 2, 4 UNION ALL 
    SELECT 3, 1 UNION ALL 
    SELECT 4, 4 UNION ALL 
    SELECT 5, 4 UNION ALL 
    SELECT 6, 1 UNION ALL 
    SELECT 7, 1 UNION ALL 
    SELECT 8, 5 UNION ALL 
    SELECT 9, 5 UNION ALL 
    SELECT 10, 1 UNION ALL 
    SELECT 11, 4 UNION ALL 
    SELECT 12, 2 UNION ALL 
    SELECT 13, 8 UNION ALL 
    SELECT 14, 3 UNION ALL 
    SELECT 15, 4 UNION ALL 
    SELECT 16, 11 UNION ALL 
    SELECT 17, 5 UNION ALL 
    SELECT 18, 5SELECT [a1],[no]
    FROM @TB AS T
    WHERE NOT EXISTS(SELECT * FROM @TB WHERE [a1]=T.[a1] AND [no]>T.[no])
    ORDER BY [a1]
    /*
    a1          no
    ----------- -----------
    1           10
    2           12
    3           14
    4           15
    5           18
    8           13
    10          1
    11          16
    */
      

  5.   

    ....看反了select a1,no from tb a where 
    not exists
    (select 1 from tb where  a1=a.a1 and no>a.no)
      

  6.   

    ----------------------------------------------------------------
    -- Author :fredrickhu(小F 向高手学习)
    -- Date   :2009-07-09 13:51:54
    ----------------------------------------------------------------
    --> 测试数据:[tb]
    if object_id('[tb]') is not null drop table [tb]
    create table [tb]([no] int,[a1] int)
    insert [tb]
    select 1,10 union all
    select 2,4 union all
    select 3,1 union all
    select 4,4 union all
    select 5,4 union all
    select 6,1 union all
    select 7,1 union all
    select 8,5 union all
    select 9,5 union all
    select 10,1 union all
    select 11,4 union all
    select 12,2 union all
    select 13,8 union all
    select 14,3 union all
    select 15,4 union all
    select 16,11 union all
    select 17,5 union all
    select 18,5
    --------------开始查询--------------------------
    select * from tb a where 
    not exists
    (select 1 from tb where  a1=a.a1 and no>a.no)
    ----------------结果----------------------------
    /*no          a1          
    ----------- ----------- 
    1           10
    10          1
    12          2
    13          8
    14          3
    15          4
    16          11
    18          5(所影响的行数为 8 行)
    */
      

  7.   

    ----------------------------------------------------------------
    -- Author :fredrickhu(小F 向高手学习)
    -- Date   :2009-07-09 13:51:54
    ----------------------------------------------------------------
    --> 测试数据:[tb]
    if object_id('[tb]') is not null drop table [tb]
    create table [tb]([no] int,[a1] int)
    insert [tb]
    select 1,10 union all
    select 2,4 union all
    select 3,1 union all
    select 4,4 union all
    select 5,4 union all
    select 6,1 union all
    select 7,1 union all
    select 8,5 union all
    select 9,5 union all
    select 10,1 union all
    select 11,4 union all
    select 12,2 union all
    select 13,8 union all
    select 14,3 union all
    select 15,4 union all
    select 16,11 union all
    select 17,5 union all
    select 18,5
    --------------开始查询--------------------------
    select a1,[no] from tb a where 
    not exists
    (select 1 from tb where  a1=a.a1 and no>a.no) order by a1
    ----------------结果----------------------------
    /*a1          no          
    ----------- ----------- 
    1           10
    2           12
    3           14
    4           15
    5           18
    8           13
    10          1
    11          16(所影响的行数为 8 行)
    */