我需要编写一个sql语句来获取表格中每天的WPM计数。它将有 有些日子有多个条目;我只需要最高的WPM。此外,不包括空条目。
The data set should look like:
Date_completed, Max_WPM
date here, wpm
date here, wpm
SELECT
DISTINCT A.DATE_COMPLETED
,A.WPM Max_WPM
FROM KEYBOARD_LEARNING A
我正在尝试过滤此表的结果集中只有不同日期返回的位置。但上面的查询不起作用。如何使用WPM返回不同的日期?
DATE_completed MAX_WPM
-------------------------- ---------------
7/12/2012 ...
7/12/2012 ....
7/12/2012
7/22/2012
7/6/2012
7/12/2012
7/12/2012
7/6/2012
7/12/2012
7/12/2012
7/6/2012
7/6/2012
6/13/2012
7/12/2012
7/12/2012
7/16/2012
6/6/2012
7/6/2012
7/6/2012
6/12/2012
6/13/2012
7/6/2012
7/6/2012
7/6/2012
7/12/2012
6/13/2012
7/4/2012
6/14/2012
7/6/2012
答案 0 :(得分:1)
这听起来像你想要的
SELECT A.DATE_COMPLETED
,MAX(A.WPM) Max_WPM
FROM KEYBOARD_LEARNING A
WHERE a.wpm IS NOT NULL
GROUP BY a.date_completed
这假设DATE_COMPLETED
值中没有一个具有时间组件。如果是,则需要TRUNC
日期
SELECT TRUNC(A.DATE_COMPLETED) date_completed
,MAX(A.WPM) Max_WPM
FROM KEYBOARD_LEARNING A
WHERE a.wpm IS NOT NULL
GROUP BY TRUNC(a.date_completed)