本人新手,求一程序,谢

beginfrom0 2007-02-21 12:50:20
为了清楚,写的有点罗嗦,抱歉!数据如下:
ID ttotal Duration pid area pic
---------------------------------------------------
1 878 219 0 Content marker
2 1117 299 3 Center Pic 1
3 2553 199 2 L2 Pic 1
4 6720 120 1 L1 Pic 1
5 6860 100 1 L1 Pic 1
6 6999 259 3 Center Pic 1
7 7278 259 3 Center Pic 1
8 11106 159 0 Blank
9 11286 80 0 Blank
10 11385 718 0 Blank
11 12123 60 3 Center Pic 1
12 12203 458 3 Center Pic 1
13 12701 60 3 Center Pic 1
14 12801 179 4 R2 Pic 1
15 15473 279 0 Blank
----------------------------------------------------
16 15772 518 0 Content marker
17 17965 179 9 R2 Pic 2
18 20995 1136 8 Center Pic 2
19 22192 100 7 L2 Pic 2
20 25681 538 8 Center Pic 2
21 26239 160 8 Center Pic 2
22 26418 100 0 Blank
23 27316 100 0 Blank
24 27435 299 8 Center Pic 2
25 27754 199 8 Center Pic 2
26 29130 40 9 R2 Pic 2
27 29190 379 10 R1 Pic 2
28 29588 299 9 R2 Pic 2
29 29927 199 8 Center Pic 2
30 30904 120 0 Blank
-------------------------------------------------------
31 31104 219 0 Content marker
32 31343 279 0 Content marker
33 31961 80 13 Center Pic 3
34 40674 778 13 Center Pic 3
35 41890 817 0 Blank
36 42727 140 0 Blank
37 42887 219 13 Center Pic 3
38 43425 40 13 Center Pic 3
39 43525 179 12 L2 Pic 3
40 43724 80 12 L2 Pic 3
41 43824 40 12 L2 Pic 3
42 43924 40 13 Center Pic 3
---------------------------------------------------

数据简介:挺麻烦的数据,但没办法,ID指名每一行,ttotal是累计时间(ms),不断累加至停止;duration是相对应的后面的R2,R1,Center,L2,L1各部分的时间。Pid是对应于area的数字表示形式,与area是一一对应的;area是图片被分成的五个部分(L1,L2,CNETER,R2,R1);最后一列是pic指不同的图片。
其中area中的content和Blank忽略不计。

结果:每个图片前10秒中每一秒(1s=1000ms)五个部分(L1,L2,CENTER,R2,R1)的个数,及其对应的duration的总和及平均数(用总和除以相应的个数)。比如:对第一个图片,第一秒area里对应的L2,L1,CENTER,R1,R2的个数,然后求其对应的duration的总和,平均数(用总和除以相应的个数),第二秒area里对应的L1,L2,CENTER,R2,R1的个数。。。。然后第二个图片里area里对应的L1,L2,CENTER,R2,R1的个数,然后再求其对应的duration的总和,平均数(用总和除以相应的个数)。。。。直到结束。

结果形式最好如下:
L1_cou L2_cou Center_cou R2_cou R1_cou L1_sum L2_sum Cen_sum R2_sum R1_sum L1_ave L2_ave Cen_ave R2_ave R1_ave
Pic1_1s
Pic1_2s
Pic1_3s
.....
Pic1_10s
Pic2_1s
pic2_2s
pic2_3s
pic2_4s
.....
pic3_1s
pic3_2s
pic3_3s
......

新手:-)感激不尽,一旦成功,立马结帐。。。再次感谢!!
...全文
365 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
beginfrom0 2007-02-23
  • 打赏
  • 举报
回复
谢谢,成功,cast(((test.ttotal - t1.ttotal) / 1000) AS int) AS ttotal这个语句管事,呵呵,感激不尽......
chenkejun 2007-02-22
  • 打赏
  • 举报
回复
我用怎么没问题?
看情况问题应该是这句(test.ttotal - t1.ttotal) / 1000 AS ttotal
改成cast(((test.ttotal - t1.ttotal) / 1000) AS int) AS ttotal试试
beginfrom0 2007-02-22
  • 打赏
  • 举报
回复
好象哪里有问题???请继续帮忙,谢谢(我是个程序盲,加油中)!出来的结果是这样的
A_F_Nh_H.bmp_1s 。。。。。。。。
A_F_Nh_H.bmp_2.016s。。。。。。。。
A_F_Nh_H.bmp_2.096s。。。。。。。。
A_F_Nh_H.bmp_2.216s。。。。。。。。
A_F_Nh_H.bmp_2.275s。。。。。。。。
。。。。。。。。
(实际图名)
beginfrom0 2007-02-22
  • 打赏
  • 举报
回复
试试,感激成分!
chenkejun 2007-02-22
  • 打赏
  • 举报
回复
表test就是存数据的表
条件(area <> 'Blank') AND (area <> 'Content')可以换成pid <> 0
没注意什么优化的问题,你自己考虑吧
另外不知道你表中字段的数据类型,所以这个SQL语句可能需要对应你自己的表做些调整
chenkejun 2007-02-22
  • 打赏
  • 举报
回复
SELECT
name,
SUM(L1_sum) AS L1_sum,
SUM(L2_sum) AS L2_sum,
SUM(R1_sum) AS R1_sum,
SUM(R2_sum) AS R2_sum,
SUM(Center_sum) AS Center_sum,
SUM(L1_num) AS L1_num,
SUM(L2_num) AS L2_num,
SUM(R1_num) AS R1_num,
SUM(R2_num) AS R2_num,
SUM(Center_num) AS Center_num,
SUM(L1_ave) AS L1_ave,
SUM(L2_ave) AS L2_ave,
SUM(R1_ave) AS R1_ave,
SUM(R2_ave) AS R2_ave,
SUM(Center_ave) AS Center_ave
FROM
(SELECT
pic + '_' + CAST(ttotal + 1 AS varchar(2)) + 's' AS name,
CASE area WHEN 'L1' THEN duration END AS L1_sum,
CASE area WHEN 'L2' THEN duration END AS L2_sum,
CASE area WHEN 'R1' THEN duration END AS R1_sum,
CASE area WHEN 'R2' THEN duration END AS R2_sum,
CASE area WHEN 'Center' THEN duration END AS Center_sum,
CASE area WHEN 'L1' THEN num END AS L1_num,
CASE area WHEN 'L2' THEN num END AS L2_num,
CASE area WHEN 'R1' THEN num END AS R1_num,
CASE area WHEN 'R2' THEN num END AS R2_num,
CASE area WHEN 'Center' THEN num END AS Center_num,
CASE area WHEN 'L1' THEN duration / num END AS L1_ave,
CASE area WHEN 'L2' THEN duration / num END AS L2_ave,
CASE area WHEN 'R1' THEN duration / num END AS R1_ave,
CASE area WHEN 'R2' THEN duration / num END AS R2_ave,
CASE area WHEN 'Center' THEN duration / num END AS Center_ave
FROM
(SELECT
ttotal,
SUM(Duration) AS duration,
area,
pic,
COUNT(1) AS num
FROM
(SELECT
(test.ttotal - t1.ttotal) / 1000 AS ttotal,
test.Duration,
test.pid,
test.area,
test.pic
FROM
test INNER JOIN
(SELECT
MIN(ttotal) AS ttotal,
pic
FROM
test
WHERE
(area <> 'Blank') AND (area <> 'Content')
GROUP BY pic) AS t1
ON test.pic = t1.pic AND test.ttotal <= t1.ttotal + 10000) AS t2
GROUP BY pic, area, ttotal)AS t3) AS t4
GROUP BY name
beginfrom0 2007-02-22
  • 打赏
  • 举报
回复
全角空格隔开,呵呵,模样有点歪。。。谢谢!

ID ttotal Duration  pid  area    pic
1  878   219   0   Content  marker
2  1117   299   3   Center  Pic 1
3  2553  199    2   L2    Pic 1
4  6720  120    1   L1    Pic 1
5  6860  100    1   L1    Pic 1
6  6999  259    3   Center  Pic 1
7  7278  259    3   Center  Pic 1
8  11106  159   0   Blank
9  11286  80    0   Blank
10 11385  718    0   Blank
11 12123  60    3   Center  Pic 1
12 12203  458    3   Center  Pic 1
13 12701  60    3   Center   Pic 1
14 12801  179    4   R2    Pic 1
15 15473  279    0   Blank
-------------------------
16 15772  518    0   Content  marker
17 17965  179    9   R2    Pic 2
18 20995  1136   8   Center   Pic 2
19 22192  100    7   L2    Pic 2
20 25681  538    8   Center  Pic 2
21 26239  160    8   Center  Pic 2
22 26418  100    0   Blank
23 27316  100    0   Blank
24 27435  299    8   Center  Pic 2
25 27754  199    8   Center  Pic 2
26 29130  40    9    R2    Pic 2
27 29190  379    10   R1    Pic 2
28 29588  299    9   R2    Pic 2
29 29927  199    8   Center  Pic 2
30 30904  120    0   Blank
--------------------------
31 31104  219    0   Content  marker
32 31343  279    0   Content  marker
33 31961  80    13   Center   Pic 3
34 40674  778    13  Center   Pic 3
35 41890  817    0   Blank
36 42727  140    0   Blank
37 42887  219    13  Center   Pic 3
38 43425  40    13   Center   Pic 3
39 43525  179    12   L2    Pic 3
40 43724  80    12    L2    Pic 3
41 43824  40    12    L2    Pic 3
42 43924  40    13   Center   Pic 3
---------------------------
数据简介:挺麻烦的数据,但没办法,ID指名每一行,ttotal是累计时间(ms),不断累加至停止;duration是相对应的后面的R2,R1,Center,L2,L1各部分的时间。Pid是对应于area的数字表示形式,与area是一一对应的;area是图片被分成的五个部分(L1,L2,CNETER,R2,R1);最后一列是pic指不同的图片(提供三个)。
其中area中的content和Blank忽略不计。

结果:每个图片前10秒中每一秒(1s=1000ms)五个部分(L1,L2,CENTER,R2,R1)的个数,及其对应的duration的总和及平均数(用总和除以相应的个数)。比如:对第一个图片,第一秒area里对应的L2,L1,CENTER,R1,R2的个数,然后求其对应的duration的总和,平均数(用总和除以相应的个数),第二秒area里对应的L1,L2,CENTER,R2,R1的个数。。。。然后第二个图片里area里对应的L1,L2,CENTER,R2,R1的个数,然后再求其对应的duration的总和,平均数(用总和除以相应的个数)。。。。直到结束。

结果形式最好如下:
L1_cou L2_cou Center_cou R2_cou R1_cou L1_sum L2_sum Cen_sum R2_sum R1_sum L1_ave L2_ave Cen_ave R2_ave R1_ave
Pic1_1s
Pic1_2s
Pic1_3s
.....
Pic1_10s
Pic2_1s
pic2_2s
pic2_3s
pic2_4s
.....
pic3_1s
pic3_2s
pic3_3s
......

新手:-)感激不尽。。。


chenkejun 2007-02-22
  • 打赏
  • 举报
回复
如果ttotal是整数类型 int/int应该是取整,不应该出现小数啊
beginfrom0 2007-02-22
  • 打赏
  • 举报
回复
一大堆这样的数据:-(
beginfrom0 2007-02-22
  • 打赏
  • 举报
回复
再排过数据格式过来,如下:


ID ttotal Duration     pid area pic
1 878 219 0 Content marker
2 1117 299 3 Center Pic 1
3 2553 199 2 L2 Pic 1
4 6720 120 1 L1 Pic 1
5 6860 100 1 L1 Pic 1
6 6999 259 3 Center Pic 1
7 7278 259 3 Center Pic 1
8 11106 159 0 Blank
9 11286 80 0 Blank
10 11385 718 0 Blank
11 12123 60 3 Center Pic 1
12 12203 458 3 Center Pic 1
13 12701 60 3 Center Pic 1
14 12801 179 4 R2 Pic 1
15 15473 279 0 Blank
16 15772 518 0 Content marker
17 17965 179 9 R2 Pic 2
18 20995 1136 8 Center Pic 2
19 22192 100 7 L2 Pic 2
20 25681 538 8 Center Pic 2
21 26239 160 8 Center Pic 2
22 26418 100 0 Blank
23 27316 100 0 Blank
24 27435 299 8 Center Pic 2
25 27754 199 8 Center Pic 2
26 29130 40 9 R2 Pic 2
27 29190 379 10 R1 Pic 2
28 29588 299 9 R2 Pic 2
29 29927 199 8 Center Pic 2
30 30904 120 0 Blank
31 31104 219 0 Content marker
32 31343 279 0 Content marker
33 31961 80 13 Center Pic 3
34 40674 778 13 Center Pic 3
35 41890 817 0 Blank
36 42727 140 0 Blank
37 42887 219 13 Center Pic 3
38 43425 40 13 Center Pic 3
39 43525 179 12 L2 Pic 3
40 43724 80 12 L2 Pic 3
41 43824 40 12 L2 Pic 3
42 43924 40 13 Center Pic 3

xie_yanke 2007-02-22
  • 打赏
  • 举报
回复
用中文全角空格区别开,那样,应该就不会再变了.
beginfrom0 2007-02-22
  • 打赏
  • 举报
回复
超级郁闷,一觉醒来格式又变了,过会儿再发个新的格式。。。
beginfrom0 2007-02-21
  • 打赏
  • 举报
回复
数据描述不详处,不要客气,在线等。。。
xiaoku 2007-02-21
  • 打赏
  • 举报
回复
为什么我第一次看格式是排好了,我刷新一下就没了?
chenkejun 2007-02-21
  • 打赏
  • 举报
回复
恩,排版是种美德。
等下班后回家尝试一下吧。
不过lz一定要这种需求吗?做出来真是挺麻烦
找每个图片处理的开始时间,确定哪些是前十秒的数据
然后再做对应的数据的计算。
Eddie05 2007-02-21
  • 打赏
  • 举报
回复
顶顶
beginfrom0 2007-02-21
  • 打赏
  • 举报
回复
刚刚发现数据格式变了,唉,继续发纠正过的数据,希望这次不要再改形式。如下:
ID ttotal Duration pid area pic
-----------------------------------------------------
1 878 219 0 Content marker
2 1117 299 3 Center Pic 1
3 1437 159 3 Center Pic 1
4 1616 319 3 Center Pic 1
5 2094 40 3 Center Pic 1
6 2154 40 3 Center Pic 1
7 2254 279 3 Center Pic 1
8 2553 199 2 L2 Pic 1
9 2792 459 3 Center Pic 1
10 3271 618 3 Center Pic 1
11 3909 558 3 Center Pic 1
12 4706 299 3 Center Pic 1
13 5025 1176 3 Center Pic 1
14 6261 279 4 R2 Pic 1
15 6720 120 1 L1 Pic 1
16 6860 100 1 L1 Pic 1
17 6999 259 3 Center Pic 1
18 7278 259 3 Center Pic 1
19 7557 299 3 Center Pic 1
20 8116 60 3 Center Pic 1
21 8195 1077 3 Center Pic 1
22 9292 798 3 Center Pic 1
23 10109 279 3 Center Pic 1
24 10688 399 3 Center Pic 1
25 11106 159 0 Blank
26 11286 80 0 Blank
27 11385 718 0 Blank
28 12123 60 3 Center Pic 1
29 12203 458 3 Center Pic 1
30 12701 60 3 Center Pic 1
31 12801 179 4 R2 Pic 1
32 13020 498 3 Center Pic 1
33 13539 179 3 Center Pic 1
34 13778 40 3 Center Pic 1
35 14097 439 3 Center Pic 1
36 14556 797 3 Center Pic 1
37 15373 40 3 Center Pic 1
38 15473 279 0 Blank
-----------------------------------------------------
39 15772 518 0 Content marker
40 16469 40 8 Center Pic 2
41 16569 100 8 Center Pic 2
42 16689 1216 8 Center Pic 2
43 17965 179 9 R2 Pic 2
44 18164 279 8 Center Pic 2
45 18463 179 8 Center Pic 2
46 18663 518 8 Center Pic 2
47 19420 558 8 Center Pic 2
48 20258 518 8 Center Pic 2
49 20796 179 8 Center Pic 2
50 20995 1136 8 Center Pic 2
51 22192 100 7 L2 Pic 2
52 22331 738 8 Center Pic 2
53 23089 279 8 Center Pic 2
54 23388 478 8 Center Pic 2
55 23886 678 8 Center Pic 2
56 24803 837 8 Center Pic 2
57 25681 538 8 Center Pic 2
58 26239 160 8 Center Pic 2
59 26418 100 0 Blank
60 26538 219 0 Blank
61 26917 80 0 Blank
62 27017 279 0 Blank
63 27316 100 0 Blank
64 27435 299 8 Center Pic 2
65 27754 199 8 Center Pic 2
66 27974 259 8 Center Pic 2
67 28472 239 8 Center Pic 2
68 28731 80 8 Center Pic 2
69 29130 40 9 R2 Pic 2
70 29190 379 10 R1 Pic 2
71 29588 299 9 R2 Pic 2
72 29927 199 8 Center Pic 2
73 30147 40 8 Center Pic 2
74 30207 319 8 Center Pic 2
75 30545 159 8 Center Pic 2
76 30725 160 8 Center Pic 2
77 30904 120 0 Blank
78 31044 40 0 Blank
------------------------------------------------------
79 31104 219 0 Content marker
80 31343 279 0 Content marker
81 31961 80 13 Center Pic 3
82 32081 159 13 Center Pic 3
83 32260 678 13 Center Pic 3
84 32958 478 13 Center Pic 3
85 33456 399 13 Center Pic 3
86 34074 1336 13 Center Pic 3
87 35689 60 13 Center Pic 3
88 35769 319 13 Center Pic 3
89 36108 60 13 Center Pic 3
90 36188 80 13 Center Pic 3
91 36288 339 13 Center Pic 3
92 36646 419 13 Center Pic 3
93 37085 60 13 Center Pic 3
94 37165 518 13 Center Pic 3
95 37703 139 13 Center Pic 3
96 38082 179 13 Center Pic 3
97 38281 159 13 Center Pic 3
98 38461 199 14 R2 Pic 3
99 38700 857 13 Center Pic 3
100 39836 817 13 Center Pic 3
101 40674 778 13 Center Pic 3
102 41471 40 13 Center Pic 3
103 41531 40 13 Center Pic 3
104 41591 159 13 Center Pic 3
105 41790 80 13 Center Pic 3
106 41890 817 0 Blank
107 42727 140 0 Blank
108 42887 219 13 Center Pic 3
109 43425 40 13 Center Pic 3
110 43525 179 12 L2 Pic 3
111 43724 80 12 L2 Pic 3
112 43824 40 12 L2 Pic 3
113 43924 40 13 Center Pic 3
114 43983 279 13 Center Pic 3
115 44282 60 13 Center Pic 3
116 44382 239 11 L1 Pic 3
117 44641 120 11 L1 Pic 3
118 44821 279 13 Center Pic 3
119 45120 339 13 Center Pic 3
120 45479 159 13 Center Pic 3
121 45658 239 13 Center Pic 3
122 45917 199 13 Center Pic 3

----------------------------------------------------

27,580

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧