ID       股票代码  日期              开盘价   最高价   最低价   收盘价   成交量            成交额
1 600000 1999-11-10  29.50 29.80 27.00 27.75 174085000.00 4859102208.00
2 600000 1999-11-11  27.58 28.38 27.53 27.71 29403400.00 821582208.00
3 600000 1999-11-12  27.86 28.30 27.77 28.05 15007900.00 421591616.00
4 600000 1999-11-15  28.20 28.25 27.70 27.75 11921000.00 332952800.00
5 600000 1999-11-16  27.88 27.97 26.48 26.55 23223100.00 628908288.00
6 600000 1999-11-17  26.50 27.18 26.37 27.18 10052500.00 268995040.00
7 600000 1999-11-18  27.20 27.58 26.78 27.02 8446500.00 229577872.00
8 600000 1999-11-19  27.50 27.53 26.80 26.88 5374900.00 145887120.00
9 600000 1999-11-22  26.88 26.95 26.30 26.45 5535400.00 147086160.00
10 600000 1999-11-23  26.45 26.55 26.10 26.45 3843900.00 101224496.00
11 600000 1999-11-24  26.44 26.55 26.01 26.43 4098000.00 107344464.00
12 600000 1999-11-25  26.30 26.66 26.02 26.40 5725200.00 150528192.00
13 600000 1999-11-26  26.43 26.66 26.15 26.45 2282600.00 60508936.00
14 600000 1999-11-29   26.45 26.83 26.22 26.33 2681200.00 71099576.00
15 600000 1999-11-30   26.30 26.50 26.11 26.40 2371300.00 62335744.00
16 600000 1999-12-01   26.31 26.90 26.21 26.60 2865100.00 76287992.00
17 600000 1999-12-02  26.52 26.72 26.22 26.26 1938400.00 51110240.00
18 600000 1999-12-03  26.25 26.65 26.20 26.36 2552500.00 67291880.00
19 600000 1999-12-06   26.30 26.35 25.60 25.66 6983900.00 180516080.00
20 600000 1999-12-07   25.60 25.85 25.50 25.60 3955700.00 101467904.00
21 600000 1999-12-08   25.60 25.76 25.50 25.53 2236500.00 57214360.00
22 600000 1999-12-09   25.50 25.55 25.30 25.36 2564600.00 65136972.00
23 600000 1999-12-10   25.36 26.10 25.22 25.97 3553900.00 91041272.00
24 600000 1999-12-13   25.98 26.45 25.60 25.92 7058400.00 184655968.00
25 600000 1999-12-14   25.70 26.00 25.70 26.00 1618400.00 41845144.00
26 600000 1999-12-15   26.00 26.90 25.90 26.45 6797800.00 180407904.00
27 600000 1999-12-16   26.50 26.50 25.95 26.00 3616200.00 94601472.00
28 600000 1999-12-21   25.45 25.55 25.14 25.24 4215300.00 106523992.00
29 600000 1999-12-22   25.24 25.35 25.05 25.15 3083500.00 77614088.00
30 600000 1999-12-23   25.20 25.30 24.70 24.78 4161500.00 103557904.00
31 600000 1999-12-24   24.60 25.07 24.59 24.75 2832400.00 70142720.00
32 600000 1999-12-27   24.75 25.00 24.50 24.58 2233700.00 55170692.00
33 600000 1999-12-28   24.54 25.08 24.50 24.60 3176600.00 78430312.00
34 600000 1999-12-29   24.71 24.97 24.57 24.66 2284200.00 56436028.00
35 600000 1999-12-30   24.90 24.99 24.65 24.75 2333100.00 57888236.00
36 600000 2000-01-04  24.98 25.78 24.75 25.57 4496000.00 113946784.00
37 600000 2000-01-05   25.57 25.98 25.15 25.28 5252800.00 134465424.00
38 600000 2000-01-06   25.18 26.30 25.05 25.99 6229600.00 160059792.00
39 600000 2000-01-07   26.30 27.50 26.12 26.90 21355300.00 575751104.00
40 600000 2000-01-10   27.00 27.85 26.71 27.25 16539700.00 450453504.00
41 600000 2000-01-11   27.25 27.30 26.12 26.20 9390700.00 251055904.00
42 600000 2000-01-12  26.00 26.00 24.80 25.12 35274900.00 889867328.00
43 600000 2000-01-13   25.00 25.25 24.80 24.90 7975600.00 199244304.00这是股票数据,我想求股票收盘价大于开盘价的连续次数的概率分布
形成的结果是:
连续上涨天数 次数
1        15
2        20
3        3

解决方案 »

  1.   

    Group By
    感觉没有什么难的啊
      

  2.   

    create table tb(ID int,dm varchar(6),dt datetime,s decimal(6,2),m decimal(6,2),n decimal(6,2),e decimal(6,2),vl decimal(12,2),ve decimal(12,2))
    insert into tb select 1,'600000','1999-11-10',29.50,29.80,27.00,27.75,174085000.00,4859102208.00 union all select 
    2,'600000','1999-11-11',27.58,28.38,27.53,27.71,29403400.00,821582208.00 union all select
    3,'600000','1999-11-12',27.86,28.30,27.77,28.05,15007900.00,421591616.00 union all select
    4,'600000','1999-11-15',28.20,28.25,27.70,27.75,11921000.00,332952800.00 union all select
    5,'600000','1999-11-16',27.88,27.97,26.48,26.55,23223100.00,628908288.00 union all select
    6,'600000','1999-11-17',26.50,27.18,26.37,27.18,10052500.00,268995040.00 union all select
    7,'600000','1999-11-18',27.20,27.58,26.78,27.02,8446500.00,229577872.00 union all select
    8,'600000','1999-11-19',27.50,27.53,26.80,26.88,5374900.00,145887120.00 union all select
    9,'600000','1999-11-22',26.88,26.95,26.30,26.45,5535400.00,147086160.00 union all select
    10,'600000','1999-11-23',26.45,26.55,26.10,26.45,3843900.00,101224496.00 union all select
    11,'600000','1999-11-24',26.44,26.55,26.01,26.43,4098000.00,107344464.00 union all select
    12,'600000','1999-11-25',26.30,26.66,26.02,26.40,5725200.00,150528192.00 union all select
    13,'600000','1999-11-26',26.43,26.66,26.15,26.45,2282600.00,60508936.00 union all select
    14,'600000','1999-11-29',26.45,26.83,26.22,26.33,2681200.00,71099576.00 union all select
    15,'600000','1999-11-30',26.30,26.50,26.11,26.40,2371300.00,62335744.00 union all select
    16,'600000','1999-12-01',26.31,26.90,26.21,26.60,2865100.00,76287992.00 union all select
    17,'600000','1999-12-02',26.52,26.72,26.22,26.26,1938400.00,51110240.00 union all select
    18,'600000','1999-12-03',26.25,26.65,26.20,26.36,2552500.00,67291880.00 union all select
    19,'600000','1999-12-06',26.30,26.35,25.60,25.66,6983900.00,180516080.00 union all select
    20,'600000','1999-12-07',25.60,25.85,25.50,25.60,3955700.00,101467904.00 union all select
    21,'600000','1999-12-08',25.60,25.76,25.50,25.53,2236500.00,57214360.00 union all select
    22,'600000','1999-12-09',25.50,25.55,25.30,25.36,2564600.00,65136972.00 union all select
    23,'600000','1999-12-10',25.36,26.10,25.22,25.97,3553900.00,91041272.00 union all select
    24,'600000','1999-12-13',25.98,26.45,25.60,25.92,7058400.00,184655968.00 union all select
    25,'600000','1999-12-14',25.70,26.00,25.70,26.00,1618400.00,41845144.00 union all select
    26,'600000','1999-12-15',26.00,26.90,25.90,26.45,6797800.00,180407904.00 union all select
    27,'600000','1999-12-16',26.50,26.50,25.95,26.00,3616200.00,94601472.00 union all select
    28,'600000','1999-12-21',25.45,25.55,25.14,25.24,4215300.00,106523992.00 union all select
    29,'600000','1999-12-22',25.24,25.35,25.05,25.15,3083500.00,77614088.00 union all select
    30,'600000','1999-12-23',25.20,25.30,24.70,24.78,4161500.00,103557904.00 union all select
    31,'600000','1999-12-24',24.60,25.07,24.59,24.75,2832400.00,70142720.00 union all select
    32,'600000','1999-12-27',24.75,25.00,24.50,24.58,2233700.00,55170692.00 union all select
    33,'600000','1999-12-28',24.54,25.08,24.50,24.60,3176600.00,78430312.00 union all select
    34,'600000','1999-12-29',24.71,24.97,24.57,24.66,2284200.00,56436028.00 union all select
    35,'600000','1999-12-30',24.90,24.99,24.65,24.75,2333100.00,57888236.00 union all select
    36,'600000','2000-01-04',24.98,25.78,24.75,25.57,4496000.00,113946784.00 union all select
    37,'600000','2000-01-05',25.57,25.98,25.15,25.28,5252800.00,134465424.00 union all select
    38,'600000','2000-01-06',25.18,26.30,25.05,25.99,6229600.00,160059792.00 union all select
    39,'600000','2000-01-07',26.30,27.50,26.12,26.90,21355300.00,575751104.00 union all select
    40,'600000','2000-01-10',27.00,27.85,26.71,27.25,16539700.00,450453504.00 union all select
    41,'600000','2000-01-11',27.25,27.30,26.12,26.20,9390700.00,251055904.00 union all select
    42,'600000','2000-01-12',26.00,26.00,24.80,25.12,35274900.00,889867328.00 union all select
    43,'600000','2000-01-13',25.00,25.25,24.80,24.90,7975600.00,199244304.00
    go
    with cte as(
    select id from tb where e>s
    )select 1,convert(decimal(4,2),count(*))*100/(select count(*) from tb) from cte a where not exists(select 1 from cte where id=a.id+1 or id=a.id-1)
    union all
    select 2,convert(decimal(4,2),count(*))*100/(select count(*) from tb) from cte a where not exists(select 1 from cte where id=a.id+2 or id=a.id-1) and exists(select 1 from cte where id=a.id+1)
    union all
    select 3,convert(decimal(4,2),count(*))*100/(select count(*) from tb) from cte a where not exists(select 1 from cte where id=a.id+3 or id=a.id-1) and exists(select 1 from cte where id=a.id+1) and exists(select 1 from cte where id=a.id+2)
    union all
    select 4,convert(decimal(4,2),count(*))*100/(select count(*) from tb) from cte a where not exists(select 1 from cte where id=a.id+4 or id=a.id-1) and exists(select 1 from cte where id=a.id+1) and exists(select 1 from cte where id=a.id+2) and exists(select 1 from cte where id=a.id+3)
    go
    drop table tb
    /*
    ----------- ---------------------------------------
    1           13.9534883720930
    2           9.3023255813953
    3           2.3255813953488
    4           0.0000000000000(4 行受影响)*/
      

  3.   

    create table tb(ID int,dm varchar(6),dt datetime,s decimal(6,2),m decimal(6,2),n decimal(6,2),e decimal(6,2),vl decimal(12,2),ve decimal(12,2))
    insert into tb select 1,'600000','1999-11-10',29.50,29.80,27.00,27.75,174085000.00,4859102208.00 union all select 
    2,'600000','1999-11-11',27.58,28.38,27.53,27.71,29403400.00,821582208.00 union all select
    3,'600000','1999-11-12',27.86,28.30,27.77,28.05,15007900.00,421591616.00 union all select
    4,'600000','1999-11-15',28.20,28.25,27.70,27.75,11921000.00,332952800.00 union all select
    5,'600000','1999-11-16',27.88,27.97,26.48,26.55,23223100.00,628908288.00 union all select
    6,'600000','1999-11-17',26.50,27.18,26.37,27.18,10052500.00,268995040.00 union all select
    7,'600000','1999-11-18',27.20,27.58,26.78,27.02,8446500.00,229577872.00 union all select
    8,'600000','1999-11-19',27.50,27.53,26.80,26.88,5374900.00,145887120.00 union all select
    9,'600000','1999-11-22',26.88,26.95,26.30,26.45,5535400.00,147086160.00 union all select
    10,'600000','1999-11-23',26.45,26.55,26.10,26.45,3843900.00,101224496.00 union all select
    11,'600000','1999-11-24',26.44,26.55,26.01,26.43,4098000.00,107344464.00 union all select
    12,'600000','1999-11-25',26.30,26.66,26.02,26.40,5725200.00,150528192.00 union all select
    13,'600000','1999-11-26',26.43,26.66,26.15,26.45,2282600.00,60508936.00 union all select
    14,'600000','1999-11-29',26.45,26.83,26.22,26.33,2681200.00,71099576.00 union all select
    15,'600000','1999-11-30',26.30,26.50,26.11,26.40,2371300.00,62335744.00 union all select
    16,'600000','1999-12-01',26.31,26.90,26.21,26.60,2865100.00,76287992.00 union all select
    17,'600000','1999-12-02',26.52,26.72,26.22,26.26,1938400.00,51110240.00 union all select
    18,'600000','1999-12-03',26.25,26.65,26.20,26.36,2552500.00,67291880.00 union all select
    19,'600000','1999-12-06',26.30,26.35,25.60,25.66,6983900.00,180516080.00 union all select
    20,'600000','1999-12-07',25.60,25.85,25.50,25.60,3955700.00,101467904.00 union all select
    21,'600000','1999-12-08',25.60,25.76,25.50,25.53,2236500.00,57214360.00 union all select
    22,'600000','1999-12-09',25.50,25.55,25.30,25.36,2564600.00,65136972.00 union all select
    23,'600000','1999-12-10',25.36,26.10,25.22,25.97,3553900.00,91041272.00 union all select
    24,'600000','1999-12-13',25.98,26.45,25.60,25.92,7058400.00,184655968.00 union all select
    25,'600000','1999-12-14',25.70,26.00,25.70,26.00,1618400.00,41845144.00 union all select
    26,'600000','1999-12-15',26.00,26.90,25.90,26.45,6797800.00,180407904.00 union all select
    27,'600000','1999-12-16',26.50,26.50,25.95,26.00,3616200.00,94601472.00 union all select
    28,'600000','1999-12-21',25.45,25.55,25.14,25.24,4215300.00,106523992.00 union all select
    29,'600000','1999-12-22',25.24,25.35,25.05,25.15,3083500.00,77614088.00 union all select
    30,'600000','1999-12-23',25.20,25.30,24.70,24.78,4161500.00,103557904.00 union all select
    31,'600000','1999-12-24',24.60,25.07,24.59,24.75,2832400.00,70142720.00 union all select
    32,'600000','1999-12-27',24.75,25.00,24.50,24.58,2233700.00,55170692.00 union all select
    33,'600000','1999-12-28',24.54,25.08,24.50,24.60,3176600.00,78430312.00 union all select
    34,'600000','1999-12-29',24.71,24.97,24.57,24.66,2284200.00,56436028.00 union all select
    35,'600000','1999-12-30',24.90,24.99,24.65,24.75,2333100.00,57888236.00 union all select
    36,'600000','2000-01-04',24.98,25.78,24.75,25.57,4496000.00,113946784.00 union all select
    37,'600000','2000-01-05',25.57,25.98,25.15,25.28,5252800.00,134465424.00 union all select
    38,'600000','2000-01-06',25.18,26.30,25.05,25.99,6229600.00,160059792.00 union all select
    39,'600000','2000-01-07',26.30,27.50,26.12,26.90,21355300.00,575751104.00 union all select
    40,'600000','2000-01-10',27.00,27.85,26.71,27.25,16539700.00,450453504.00 union all select
    41,'600000','2000-01-11',27.25,27.30,26.12,26.20,9390700.00,251055904.00 union all select
    42,'600000','2000-01-12',26.00,26.00,24.80,25.12,35274900.00,889867328.00 union all select
    43,'600000','2000-01-13',25.00,25.25,24.80,24.90,7975600.00,199244304.00
    go
    with cte as(
    select id from tb where e>s
    )select 1 as 连续上涨天数,convert(decimal(4,2),count(*)) as 次数from cte a where not exists(select 1 from cte where id=a.id+1 or id=a.id-1)
    union all
    select 2,convert(decimal(4,2),count(*)) from cte a where not exists(select 1 from cte where id=a.id+2 or id=a.id-1) and exists(select 1 from cte where id=a.id+1)
    union all
    select 3,convert(decimal(4,2),count(*)) from cte a where not exists(select 1 from cte where id=a.id+3 or id=a.id-1) and exists(select 1 from cte where id=a.id+1) and exists(select 1 from cte where id=a.id+2)
    union all
    select 4,convert(decimal(4,2),count(*)) from cte a where not exists(select 1 from cte where id=a.id+4 or id=a.id-1) and exists(select 1 from cte where id=a.id+1) and exists(select 1 from cte where id=a.id+2) and exists(select 1 from cte where id=a.id+3)
    go
    drop table tb
    /*连续上涨天数 次数
    1 6.00
    2 4.00
    3 1.00
    4 0.00*/
      

  4.   

    create table tb(ID int,dm varchar(6),dt datetime,s decimal(6,2),m decimal(6,2),n decimal(6,2),e decimal(6,2),vl decimal(12,2),ve decimal(12,2))
    insert into tb select 1,'600000','1999-11-10',29.50,29.80,27.00,27.75,174085000.00,4859102208.00 union all select 
    2,'600000','1999-11-11',27.58,28.38,27.53,27.71,29403400.00,821582208.00 union all select
    3,'600000','1999-11-12',27.86,28.30,27.77,28.05,15007900.00,421591616.00 union all select
    4,'600000','1999-11-15',28.20,28.25,27.70,27.75,11921000.00,332952800.00 union all select
    5,'600000','1999-11-16',27.88,27.97,26.48,26.55,23223100.00,628908288.00 union all select
    6,'600000','1999-11-17',26.50,27.18,26.37,27.18,10052500.00,268995040.00 union all select
    7,'600000','1999-11-18',27.20,27.58,26.78,27.02,8446500.00,229577872.00 union all select
    8,'600000','1999-11-19',27.50,27.53,26.80,26.88,5374900.00,145887120.00 union all select
    9,'600000','1999-11-22',26.88,26.95,26.30,26.45,5535400.00,147086160.00 union all select
    10,'600000','1999-11-23',26.45,26.55,26.10,26.45,3843900.00,101224496.00 union all select
    11,'600000','1999-11-24',26.44,26.55,26.01,26.43,4098000.00,107344464.00 union all select
    12,'600000','1999-11-25',26.30,26.66,26.02,26.40,5725200.00,150528192.00 union all select
    13,'600000','1999-11-26',26.43,26.66,26.15,26.45,2282600.00,60508936.00 union all select
    14,'600000','1999-11-29',26.45,26.83,26.22,26.33,2681200.00,71099576.00 union all select
    15,'600000','1999-11-30',26.30,26.50,26.11,26.40,2371300.00,62335744.00 union all select
    16,'600000','1999-12-01',26.31,26.90,26.21,26.60,2865100.00,76287992.00 union all select
    17,'600000','1999-12-02',26.52,26.72,26.22,26.26,1938400.00,51110240.00 union all select
    18,'600000','1999-12-03',26.25,26.65,26.20,26.36,2552500.00,67291880.00 union all select
    19,'600000','1999-12-06',26.30,26.35,25.60,25.66,6983900.00,180516080.00 union all select
    20,'600000','1999-12-07',25.60,25.85,25.50,25.60,3955700.00,101467904.00 union all select
    21,'600000','1999-12-08',25.60,25.76,25.50,25.53,2236500.00,57214360.00 union all select
    22,'600000','1999-12-09',25.50,25.55,25.30,25.36,2564600.00,65136972.00 union all select
    23,'600000','1999-12-10',25.36,26.10,25.22,25.97,3553900.00,91041272.00 union all select
    24,'600000','1999-12-13',25.98,26.45,25.60,25.92,7058400.00,184655968.00 union all select
    25,'600000','1999-12-14',25.70,26.00,25.70,26.00,1618400.00,41845144.00 union all select
    26,'600000','1999-12-15',26.00,26.90,25.90,26.45,6797800.00,180407904.00 union all select
    27,'600000','1999-12-16',26.50,26.50,25.95,26.00,3616200.00,94601472.00 union all select
    28,'600000','1999-12-21',25.45,25.55,25.14,25.24,4215300.00,106523992.00 union all select
    29,'600000','1999-12-22',25.24,25.35,25.05,25.15,3083500.00,77614088.00 union all select
    30,'600000','1999-12-23',25.20,25.30,24.70,24.78,4161500.00,103557904.00 union all select
    31,'600000','1999-12-24',24.60,25.07,24.59,24.75,2832400.00,70142720.00 union all select
    32,'600000','1999-12-27',24.75,25.00,24.50,24.58,2233700.00,55170692.00 union all select
    33,'600000','1999-12-28',24.54,25.08,24.50,24.60,3176600.00,78430312.00 union all select
    34,'600000','1999-12-29',24.71,24.97,24.57,24.66,2284200.00,56436028.00 union all select
    35,'600000','1999-12-30',24.90,24.99,24.65,24.75,2333100.00,57888236.00 union all select
    36,'600000','2000-01-04',24.98,25.78,24.75,25.57,4496000.00,113946784.00 union all select
    37,'600000','2000-01-05',25.57,25.98,25.15,25.28,5252800.00,134465424.00 union all select
    38,'600000','2000-01-06',25.18,26.30,25.05,25.99,6229600.00,160059792.00 union all select
    39,'600000','2000-01-07',26.30,27.50,26.12,26.90,21355300.00,575751104.00 union all select
    40,'600000','2000-01-10',27.00,27.85,26.71,27.25,16539700.00,450453504.00 union all select
    41,'600000','2000-01-11',27.25,27.30,26.12,26.20,9390700.00,251055904.00 union all select
    42,'600000','2000-01-12',26.00,26.00,24.80,25.12,35274900.00,889867328.00 union all select
    43,'600000','2000-01-13',25.00,25.25,24.80,24.90,7975600.00,199244304.00
    go
    with cte as(
    select id from tb where e>s
    )select 1 as 连续上涨天数,count(*) as 次数from cte a where not exists(select 1 from cte where id=a.id+1 or id=a.id-1)
    union all
    select 2,count(*) from cte a where not exists(select 1 from cte where id=a.id+2 or id=a.id-1) and exists(select 1 from cte where id=a.id+1)
    union all
    select 3,count(*) from cte a where not exists(select 1 from cte where id=a.id+3 or id=a.id-1) and exists(select 1 from cte where id=a.id+1) and exists(select 1 from cte where id=a.id+2)
    union all
    select 4,count(*) from cte a where not exists(select 1 from cte where id=a.id+4 or id=a.id-1) and exists(select 1 from cte where id=a.id+1) and exists(select 1 from cte where id=a.id+2) and exists(select 1 from cte where id=a.id+3)
    go
    drop table tb
    /*连续上涨天数 次数
    1 6
    2 4
    3 1
    4 0*/