选择一列中具有非空值的所有最新记录的与众不同的关键字 [英] SELECT all the newest record distinct keyword with a non null value in one column
本文介绍了选择一列中具有非空值的所有最新记录的与众不同的关键字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
接着这个问题 选择非null的最新记录一栏中的值
我知道在哪里有这些数据
I know have a problem where I have this data
id | keyword | count | date
1 | ipod | 200 | 2009-08-02
2 | ipod | 250 | 2009-09-01
3 | ipod | 150 | 2009-09-04
4 | ipod | NULL | 2009-09-07
5 | apple | 100 | 2009-07-01
6 | apple | 98 | 2009-07-05
7 | apple | 500 | 2009-07-30
8 | itunes | NULL | 2009-08-30
9 | itunes | 50 | 2009-09-10
10 | itunes | NULL | 2009-09-15
并且需要一个查询,该查询将获取行 3、7和9 日期为最新且非空的行.
And need a query which will fetch out rows 3, 7 and 9 Row which has the newest date and is non-null.
推荐答案
使用:
SELECT t.id,
t.keyword,
t.count,
t.date
FROM TABLE t
JOIN (SELECT t.keyword,
MAX(t.date) 'max_date'
FROM TABLE t
WHERE t.count IS NOT NULL
GROUP BY t.keyword) x ON x.keyword = t.keyword
AND x.max_date = t.date
这篇关于选择一列中具有非空值的所有最新记录的与众不同的关键字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文