这个sql怎么写? ( 积分: 50 )

  • 主题发起人 主题发起人 eaglepsm
  • 开始时间 开始时间
E

eaglepsm

Unregistered / Unconfirmed
GUEST, unregistred user!
表“复习记录”内容如下:
id UserLibID 单词 复习时间 陌生程度
1 9333 evolve 2005-9-16 9:23:10 5
2 9320 allure 2005-9-16 10:57:56 9
3 9319 alluring 2005-9-16 10:57:59 9
4 9354 wither 2005-9-16 11:31:39 7
5 9349 cater 2005-9-16 11:53:20 8
6 9344 preside 2005-9-16 11:53:50 11
7 9338 hip 2005-9-16 11:54:21 10
8 9349 cater 2005-9-16 12:02:59 12
9 9344 preside 2005-9-16 12:03:14 12
10 9320 allure 2005-9-16 12:08:00 11
11 9313 unbounded 2005-9-16 12:08:10 11
12 9313 unbounded 2005-9-16 12:08:45 12
13 9332 terrestrial 2005-9-16 12:42:31 12
14 9332 terrestrial 2005-9-16 12:43:57 13
15 9344 preside 2005-9-16 12:44:19 12
16 9344 preside 2005-9-16 12:44:28 11
17 9344 preside 2005-9-16 14:03:17 10
18 9293 indecent 2005-9-16 14:24:41 4
19 9300 embrace 2005-9-16 14:24:44 5
20 9369 echo 2005-9-16 14:25:07 4
21 9369 echo 2005-9-16 14:25:21 3
22 9296 nasty 2005-9-16 14:25:25 4
23 9296 nasty 2005-9-16 14:25:40 3
24 9295 gamble 2005-9-16 14:25:44 4
25 9295 gamble 2005-9-16 14:25:48 3
26 9294 gamble 2005-9-16 14:25:51 4
27 9294 gamble 2005-9-16 14:26:09 3
28 9311 estate 2005-9-16 14:26:10 4
29 9311 estate 2005-9-16 14:26:19 3
30 9291 fascinate 2005-9-16 14:26:20 4
31 9291 fascinate 2005-9-16 14:26:28 3
32 9333 evolve 2005-9-16 14:26:30 2
33 9333 evolve 2005-9-16 14:26:46 1
34 9362 itinerary 2005-9-16 14:26:47 8
35 9362 itinerary 2005-9-16 14:26:59 9
36 9365 haven 2005-9-16 14:27:07 10
37 9365 haven 2005-9-16 14:27:26 11
38 9365 haven 2005-9-16 14:27:44 11
39 9344 preside 2005-9-16 14:42:38 12
40 9345 stuck 2005-9-16 14:42:42 9
41 9345 stuck 2005-9-16 14:42:49 8
42 9346 sign off 2005-9-16 14:42:51 11
43 9346 sign off 2005-9-16 14:42:59 10
44 9346 sign off 2005-9-16 14:43:05 9
45 9347 likewise 2005-9-16 14:43:06 11
46 9347 likewise 2005-9-16 14:43:14 10
47 9348 likewise 2005-9-16 14:43:18 9
48 9348 likewise 2005-9-16 14:43:21 8
49 9349 cater 2005-9-16 14:43:22 13
50 9349 cater 2005-9-16 14:43:44 9
51 9350 inclination 2005-9-16 14:43:48 7
52 9350 inclination 2005-9-16 14:43:57 6
53 9351 governance 2005-9-16 14:43:58 9
54 9351 governance 2005-9-16 14:44:00 8
55 9352 sustain 2005-9-16 14:44:01 11
56 9352 sustain 2005-9-16 14:44:24 10
57 9353 subset 2005-9-16 14:44:25 7
58 9353 subset 2005-9-16 14:44:27 6
59 9354 wither 2005-9-16 14:44:28 10
60 9354 wither 2005-9-16 14:44:36 9
61 9355 wither 2005-9-16 14:44:37 9
62 9355 wither 2005-9-16 14:44:39 8
63 9356 apart from 2005-9-16 14:44:40 8
64 9356 apart from 2005-9-16 14:44:44 7
65 9357 scheme 2005-9-16 14:44:45 11
66 9357 scheme 2005-9-16 14:45:06 10
67 9358 scheme 2005-9-16 14:45:07 10
68 9358 scheme 2005-9-16 14:45:09 9
69 9359 sue 2005-9-16 14:45:10 9
70 9359 sue 2005-9-16 14:45:14 8
71 9360 sue 2005-9-16 14:45:15 9
72 9360 sue 2005-9-16 14:45:19 8
73 9361 fanfare 2005-9-16 14:45:20 11
74 9361 fanfare 2005-9-16 14:45:30 12
75 9362 itinerary 2005-9-16 14:46:03 9
76 9362 itinerary 2005-9-16 14:46:20 10
77 9363 sanction 2005-9-16 14:46:22 11
78 9363 sanction 2005-9-16 14:46:34 12
79 9364 sanction 2005-9-16 14:46:57 11
80 9364 sanction 2005-9-16 14:47:01 10
81 9365 haven 2005-9-16 14:47:02 11
82 9365 haven 2005-9-16 14:47:06 10
83 9366 echo 2005-9-16 14:47:07 9
84 9366 echo 2005-9-16 14:47:20 8
85 9367 echo 2005-9-16 14:47:21 10
86 9367 echo 2005-9-16 14:47:23 9
87 9368 echo 2005-9-16 14:47:24 9
88 9368 echo 2005-9-16 14:47:28 8
89 9369 echo 2005-9-16 14:47:29 3
90 9369 echo 2005-9-16 14:47:32 2
91 9370 self-contained 2005-9-16 14:47:33 8
92 9370 self-contained 2005-9-16 14:47:40 7
93 9370 self-contained 2005-9-16 14:47:41 7
94 9370 self-contained 2005-9-16 14:47:44 6
95 9332 terrestrial 2005-9-16 15:22:21 12
96 9329 unmoderated 2005-9-16 15:22:23 12
97 9329 unmoderated 2005-9-16 15:23:06 13
98 9293 indecent 2005-9-16 15:41:39 3
99 9319 alluring 2005-9-16 15:42:24 9
100 9297 psyche 2005-9-16 18:11:58 8
101 9298 frontier 2005-9-16 18:12:00 10
102 9298 frontier 2005-9-16 18:12:21 9
103 9299 hanker 2005-9-16 18:12:27 10
104 9303 conceivable 2005-9-16 18:12:44 9
105 9303 conceivable 2005-9-16 18:12:47 8
106 9304 constituency 2005-9-16 18:12:49 9
107 9304 constituency 2005-9-16 18:12:52 8
108 9305 flirtatious 2005-9-16 18:12:54 11
109 9305 flirtatious 2005-9-16 18:13:21 12
110 9306 Hungarian 2005-9-16 18:13:23 9
111 9306 Hungarian 2005-9-16 18:13:26 8
112 9307 get along 2005-9-16 18:13:27 8
113 9307 get along 2005-9-16 18:13:29 7
114 9308 provoke 2005-9-16 18:13:30 8
115 9308 provoke 2005-9-16 18:13:33 7
116 9309 crackdown 2005-9-16 18:13:34 9
117 9309 crackdown 2005-9-16 18:13:45 8
118 9310 metaphor 2005-9-16 18:13:46 9
119 9310 metaphor 2005-9-16 18:14:18 8
120 9312 parkland 2005-9-16 18:14:20 9
121 9312 parkland 2005-9-16 18:14:32 8
122 9314 pornography 2005-9-16 18:14:33 9
123 9314 pornography 2005-9-16 18:14:44 8
124 9315 counter 2005-9-16 18:14:45 9
125 9315 counter 2005-9-16 18:15:28 8
126 9316 wicked 2005-9-16 18:15:31 9
127 9316 wicked 2005-9-16 18:15:34 8
128 9317 beam 2005-9-16 18:15:35 9
129 9317 beam 2005-9-16 18:15:44 8
130 9318 beam 2005-9-16 18:15:45 9
131 9322 jurisdiction 2005-9-16 18:15:59 12
132 9322 jurisdiction 2005-9-16 18:16:10 13
133 9316 wicked 2005-9-16 18:17:48 7
134 9317 beam 2005-9-16 18:17:51 8
135 9317 beam 2005-9-16 18:18:11 8
136 9317 beam 2005-9-16 18:18:22 4
137 9318 beam 2005-9-16 18:18:23 9
138 9318 beam 2005-9-16 18:18:31 8
139 9322 jurisdiction 2005-9-16 18:18:32 13
140 9322 jurisdiction 2005-9-16 18:18:41 14
141 9323 territory 2005-9-16 18:18:44 10
142 9323 territory 2005-9-16 18:19:02 9
143 9324 consensual 2005-9-16 18:19:04 12
144 9324 consensual 2005-9-16 18:19:18 11
145 9325 sign up 2005-9-16 18:19:19 10
146 9325 sign up 2005-9-16 18:19:46 11
147 9326 CompuServe 2005-9-16 18:19:48 8
148 9326 CompuServe 2005-9-16 18:19:51 7
149 9327 supervise 2005-9-16 18:19:52 8
150 9327 supervise 2005-9-16 18:19:55 7
151 9328 start out 2005-9-16 18:19:57 9
152 9330 keep out 2005-9-16 18:20:27 10
153 9330 keep out 2005-9-16 18:20:40 9
154 9331 extraneous 2005-9-16 18:20:41 11
155 9331 extraneous 2005-9-16 18:20:53 10
156 9334 band 2005-9-16 18:21:09 9
157 9334 band 2005-9-16 18:21:18 8
158 9335 affluent 2005-9-16 18:21:19 12
159 9335 affluent 2005-9-16 18:21:44 11
160 9336 prodigy 2005-9-16 18:21:45 12
161 9336 prodigy 2005-9-16 18:21:55 13
171 9341 flourish 2005-9-16 18:23:13 5
172 9322 jurisdiction 2005-9-16 18:26:17 15
173 9336 prodigy 2005-9-16 18:26:21 13
174 9336 prodigy 2005-9-16 18:26:40 14
175 9344 preside 2005-9-16 18:26:41 12
176 9344 preside 2005-9-16 18:26:55 11
177 9332 terrestrial 2005-9-16 18:26:56 12
178 9332 terrestrial 2005-9-16 18:27:26 11
179 9338 hip 2005-9-16 18:27:27 12
180 9322 jurisdiction 2005-9-16 18:37:57 16
181 9336 prodigy 2005-9-16 18:38:42 14
182 9305 flirtatious 2005-9-16 18:39:13 12
183 9305 flirtatious 2005-9-16 18:39:46 11
184 9363 sanction 2005-9-16 18:39:48 12
185 9363 sanction 2005-9-16 18:39:59 13
186 9313 unbounded 2005-9-16 18:40:01 12
187 9313 unbounded 2005-9-16 18:40:24 13
188 9361 fanfare 2005-9-16 18:40:26 12
189 9361 fanfare 2005-9-16 18:40:37 13
190 9361 fanfare 2005-9-16 18:42:54 13

现在我需要找出复习次数少(比如小于7次),而且最近一次复习的陌生程度高的单词(比如大于5),最后得到的视图大概应该是这样的:
id UserLibID 单词 复习次数 最后复习时间 最后一次复习的陌生程度
186 9313 unbounded 4 2005-9-16 18:40 12
127 9316 wicked 3 2005-9-16 18:15 8
180 9322 jurisdiction 6 2005-9-16 18:37 16


不知道这样的SQL语句怎么写?(access数据库)
 
表“复习记录”内容如下:
id UserLibID 单词 复习时间 陌生程度
1 9333 evolve 2005-9-16 9:23:10 5
2 9320 allure 2005-9-16 10:57:56 9
3 9319 alluring 2005-9-16 10:57:59 9
4 9354 wither 2005-9-16 11:31:39 7
5 9349 cater 2005-9-16 11:53:20 8
6 9344 preside 2005-9-16 11:53:50 11
7 9338 hip 2005-9-16 11:54:21 10
8 9349 cater 2005-9-16 12:02:59 12
9 9344 preside 2005-9-16 12:03:14 12
10 9320 allure 2005-9-16 12:08:00 11
11 9313 unbounded 2005-9-16 12:08:10 11
12 9313 unbounded 2005-9-16 12:08:45 12
13 9332 terrestrial 2005-9-16 12:42:31 12
14 9332 terrestrial 2005-9-16 12:43:57 13
15 9344 preside 2005-9-16 12:44:19 12
16 9344 preside 2005-9-16 12:44:28 11
17 9344 preside 2005-9-16 14:03:17 10
18 9293 indecent 2005-9-16 14:24:41 4
19 9300 embrace 2005-9-16 14:24:44 5
20 9369 echo 2005-9-16 14:25:07 4
21 9369 echo 2005-9-16 14:25:21 3
22 9296 nasty 2005-9-16 14:25:25 4
23 9296 nasty 2005-9-16 14:25:40 3
24 9295 gamble 2005-9-16 14:25:44 4
25 9295 gamble 2005-9-16 14:25:48 3
26 9294 gamble 2005-9-16 14:25:51 4
27 9294 gamble 2005-9-16 14:26:09 3
28 9311 estate 2005-9-16 14:26:10 4
29 9311 estate 2005-9-16 14:26:19 3
30 9291 fascinate 2005-9-16 14:26:20 4
31 9291 fascinate 2005-9-16 14:26:28 3
32 9333 evolve 2005-9-16 14:26:30 2
33 9333 evolve 2005-9-16 14:26:46 1
34 9362 itinerary 2005-9-16 14:26:47 8
35 9362 itinerary 2005-9-16 14:26:59 9
36 9365 haven 2005-9-16 14:27:07 10
37 9365 haven 2005-9-16 14:27:26 11
38 9365 haven 2005-9-16 14:27:44 11
39 9344 preside 2005-9-16 14:42:38 12
40 9345 stuck 2005-9-16 14:42:42 9
41 9345 stuck 2005-9-16 14:42:49 8
42 9346 sign off 2005-9-16 14:42:51 11
43 9346 sign off 2005-9-16 14:42:59 10
44 9346 sign off 2005-9-16 14:43:05 9
45 9347 likewise 2005-9-16 14:43:06 11
46 9347 likewise 2005-9-16 14:43:14 10
47 9348 likewise 2005-9-16 14:43:18 9
48 9348 likewise 2005-9-16 14:43:21 8
49 9349 cater 2005-9-16 14:43:22 13
50 9349 cater 2005-9-16 14:43:44 9
51 9350 inclination 2005-9-16 14:43:48 7
52 9350 inclination 2005-9-16 14:43:57 6
53 9351 governance 2005-9-16 14:43:58 9
54 9351 governance 2005-9-16 14:44:00 8
55 9352 sustain 2005-9-16 14:44:01 11
56 9352 sustain 2005-9-16 14:44:24 10
57 9353 subset 2005-9-16 14:44:25 7
58 9353 subset 2005-9-16 14:44:27 6
59 9354 wither 2005-9-16 14:44:28 10
60 9354 wither 2005-9-16 14:44:36 9
61 9355 wither 2005-9-16 14:44:37 9
62 9355 wither 2005-9-16 14:44:39 8
63 9356 apart from 2005-9-16 14:44:40 8
64 9356 apart from 2005-9-16 14:44:44 7
65 9357 scheme 2005-9-16 14:44:45 11
66 9357 scheme 2005-9-16 14:45:06 10
67 9358 scheme 2005-9-16 14:45:07 10
68 9358 scheme 2005-9-16 14:45:09 9
69 9359 sue 2005-9-16 14:45:10 9
70 9359 sue 2005-9-16 14:45:14 8
71 9360 sue 2005-9-16 14:45:15 9
72 9360 sue 2005-9-16 14:45:19 8
73 9361 fanfare 2005-9-16 14:45:20 11
74 9361 fanfare 2005-9-16 14:45:30 12
75 9362 itinerary 2005-9-16 14:46:03 9
76 9362 itinerary 2005-9-16 14:46:20 10
77 9363 sanction 2005-9-16 14:46:22 11
78 9363 sanction 2005-9-16 14:46:34 12
79 9364 sanction 2005-9-16 14:46:57 11
80 9364 sanction 2005-9-16 14:47:01 10
81 9365 haven 2005-9-16 14:47:02 11
82 9365 haven 2005-9-16 14:47:06 10
83 9366 echo 2005-9-16 14:47:07 9
84 9366 echo 2005-9-16 14:47:20 8
85 9367 echo 2005-9-16 14:47:21 10
86 9367 echo 2005-9-16 14:47:23 9
87 9368 echo 2005-9-16 14:47:24 9
88 9368 echo 2005-9-16 14:47:28 8
89 9369 echo 2005-9-16 14:47:29 3
90 9369 echo 2005-9-16 14:47:32 2
91 9370 self-contained 2005-9-16 14:47:33 8
92 9370 self-contained 2005-9-16 14:47:40 7
93 9370 self-contained 2005-9-16 14:47:41 7
94 9370 self-contained 2005-9-16 14:47:44 6
95 9332 terrestrial 2005-9-16 15:22:21 12
96 9329 unmoderated 2005-9-16 15:22:23 12
97 9329 unmoderated 2005-9-16 15:23:06 13
98 9293 indecent 2005-9-16 15:41:39 3
99 9319 alluring 2005-9-16 15:42:24 9
100 9297 psyche 2005-9-16 18:11:58 8
101 9298 frontier 2005-9-16 18:12:00 10
102 9298 frontier 2005-9-16 18:12:21 9
103 9299 hanker 2005-9-16 18:12:27 10
104 9303 conceivable 2005-9-16 18:12:44 9
105 9303 conceivable 2005-9-16 18:12:47 8
106 9304 constituency 2005-9-16 18:12:49 9
107 9304 constituency 2005-9-16 18:12:52 8
108 9305 flirtatious 2005-9-16 18:12:54 11
109 9305 flirtatious 2005-9-16 18:13:21 12
110 9306 Hungarian 2005-9-16 18:13:23 9
111 9306 Hungarian 2005-9-16 18:13:26 8
112 9307 get along 2005-9-16 18:13:27 8
113 9307 get along 2005-9-16 18:13:29 7
114 9308 provoke 2005-9-16 18:13:30 8
115 9308 provoke 2005-9-16 18:13:33 7
116 9309 crackdown 2005-9-16 18:13:34 9
117 9309 crackdown 2005-9-16 18:13:45 8
118 9310 metaphor 2005-9-16 18:13:46 9
119 9310 metaphor 2005-9-16 18:14:18 8
120 9312 parkland 2005-9-16 18:14:20 9
121 9312 parkland 2005-9-16 18:14:32 8
122 9314 pornography 2005-9-16 18:14:33 9
123 9314 pornography 2005-9-16 18:14:44 8
124 9315 counter 2005-9-16 18:14:45 9
125 9315 counter 2005-9-16 18:15:28 8
126 9316 wicked 2005-9-16 18:15:31 9
127 9316 wicked 2005-9-16 18:15:34 8
128 9317 beam 2005-9-16 18:15:35 9
129 9317 beam 2005-9-16 18:15:44 8
130 9318 beam 2005-9-16 18:15:45 9
131 9322 jurisdiction 2005-9-16 18:15:59 12
132 9322 jurisdiction 2005-9-16 18:16:10 13
133 9316 wicked 2005-9-16 18:17:48 7
134 9317 beam 2005-9-16 18:17:51 8
135 9317 beam 2005-9-16 18:18:11 8
136 9317 beam 2005-9-16 18:18:22 4
137 9318 beam 2005-9-16 18:18:23 9
138 9318 beam 2005-9-16 18:18:31 8
139 9322 jurisdiction 2005-9-16 18:18:32 13
140 9322 jurisdiction 2005-9-16 18:18:41 14
141 9323 territory 2005-9-16 18:18:44 10
142 9323 territory 2005-9-16 18:19:02 9
143 9324 consensual 2005-9-16 18:19:04 12
144 9324 consensual 2005-9-16 18:19:18 11
145 9325 sign up 2005-9-16 18:19:19 10
146 9325 sign up 2005-9-16 18:19:46 11
147 9326 CompuServe 2005-9-16 18:19:48 8
148 9326 CompuServe 2005-9-16 18:19:51 7
149 9327 supervise 2005-9-16 18:19:52 8
150 9327 supervise 2005-9-16 18:19:55 7
151 9328 start out 2005-9-16 18:19:57 9
152 9330 keep out 2005-9-16 18:20:27 10
153 9330 keep out 2005-9-16 18:20:40 9
154 9331 extraneous 2005-9-16 18:20:41 11
155 9331 extraneous 2005-9-16 18:20:53 10
156 9334 band 2005-9-16 18:21:09 9
157 9334 band 2005-9-16 18:21:18 8
158 9335 affluent 2005-9-16 18:21:19 12
159 9335 affluent 2005-9-16 18:21:44 11
160 9336 prodigy 2005-9-16 18:21:45 12
161 9336 prodigy 2005-9-16 18:21:55 13
171 9341 flourish 2005-9-16 18:23:13 5
172 9322 jurisdiction 2005-9-16 18:26:17 15
173 9336 prodigy 2005-9-16 18:26:21 13
174 9336 prodigy 2005-9-16 18:26:40 14
175 9344 preside 2005-9-16 18:26:41 12
176 9344 preside 2005-9-16 18:26:55 11
177 9332 terrestrial 2005-9-16 18:26:56 12
178 9332 terrestrial 2005-9-16 18:27:26 11
179 9338 hip 2005-9-16 18:27:27 12
180 9322 jurisdiction 2005-9-16 18:37:57 16
181 9336 prodigy 2005-9-16 18:38:42 14
182 9305 flirtatious 2005-9-16 18:39:13 12
183 9305 flirtatious 2005-9-16 18:39:46 11
184 9363 sanction 2005-9-16 18:39:48 12
185 9363 sanction 2005-9-16 18:39:59 13
186 9313 unbounded 2005-9-16 18:40:01 12
187 9313 unbounded 2005-9-16 18:40:24 13
188 9361 fanfare 2005-9-16 18:40:26 12
189 9361 fanfare 2005-9-16 18:40:37 13
190 9361 fanfare 2005-9-16 18:42:54 13

现在我需要找出复习次数少(比如小于7次),而且最近一次复习的陌生程度高的单词(比如大于5),最后得到的视图大概应该是这样的:
id UserLibID 单词 复习次数 最后复习时间 最后一次复习的陌生程度
186 9313 unbounded 4 2005-9-16 18:40 12
127 9316 wicked 3 2005-9-16 18:15 8
180 9322 jurisdiction 6 2005-9-16 18:37 16


不知道这样的SQL语句怎么写?(access数据库)
 
你这问题不是用一两个SQL语句就能完成的,特别是Access数据库,那更不可能了,实现的思路大概如下:
1、统计单词的复习次数,找出你认为少的单词。
2、比较单词最近一次复习的陌生程度,找出你认为高的单词。
 
难点在于,如何显示最后一次复习时间所对应的陌生程度
 
找出次数少的单词后,用循环一个一个的比较呀,除此之外,可能没别的办法了
 
这问题看起来挺简单的,还以为可以用sql实现呢,如果用代码写的话,太不方便了,到底哪些可以用sql实现,哪些不能啊?
 
一般来说,能找出规律的就可以用SQL来实现,不过如果是ACCSESS的话,局限性就大多了,很多高级的SQL语法ACCESS都不支持的
 
前面的问题需要建立视图,特别是对复习次数,楼上几位兄弟说得比较明白了

最后一次复习的陌生程度,用单词作为distinct条件,把记录oder by 复习时间,作为一个视图

个人看法,供参考
 
我只能做到这一步了:
select 复习次数,count(复习次数),陌生程度,count(陌生程度) from hun_grou where 最后复习时间>XXX group by 复习次数,陌生程度 having count(复习次数)>7 and count(陌生程度 )>5
 
好像这样可以:
select * from
(select id,UserLibID,单词,复习次数,复习时间 as 最后一次复习时间,
(select 陌生程度 from 复习记录 where id=A.id ) as 最后一次复习的陌生程度
from
(select max(id) as id, max(userlibid) as UserLibID,max(单词) as 单词,
count(*) as 复习次数,max(复习时间) as 复习时间 from 复习记录 group by userlibid) A) B
where 复习次数<5 and 最后一次复习的陌生程度>7
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
S
回复
0
查看
1K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
911
SUNSTONE的Delphi笔记
S
D
回复
0
查看
1K
DelphiTeacher的专栏
D
后退
顶部