Sql 检查数据显示频率
我有一张桌子Sql 检查数据显示频率,sql,oracle,oracle11g,Sql,Oracle,Oracle11g,我有一张桌子 Date name interest 19990221 xxx 2.2 20110210 xxx 2.1 ... 19940922 yyy 3.3 20130930 yyy 3.3 ... 其中日期是离散的,并不是每个名字都对每年感兴趣。我想返回过去10年中每年都感兴趣的名称。请怎么做?您的日期看起来不像日期。让我假设它们是字符串: select name from table t wh
Date name interest
19990221 xxx 2.2
20110210 xxx 2.1
...
19940922 yyy 3.3
20130930 yyy 3.3
...
其中日期是离散的,并不是每个名字都对每年感兴趣。我想返回过去10年中每年都感兴趣的名称。请怎么做?您的日期看起来不像日期。让我假设它们是字符串:
select name
from table t
where to_number(substr(date, 4)) >= extract(year from sysdate) - 9
group by name
having count(distinct substr(date, 4)) = 10;
如果
日期
确实是日期
,您可以应用类似的逻辑,但函数会有点不同。谢谢您的回复。实际上我的日期是整数。请问什么是sysdate?sysdate
是Oracle中的一个“变量”,返回当前日期和时间。