[英]Oracle query for finding the records
I am not getting any result from the below 2 queries.我没有从以下 2 个查询中得到任何结果。 Please let me know if anything is wrong in this queries.如果此查询有任何问题,请告诉我。
SELECT *
FROM PERSON
where gender = 'female' and salary > '5000.50' and birth_date BETWEEN to_date('19700101', 'YYYYMMDD') + 946684800/24/60/60/1000 and to_date('19700101', 'YYYYMMDD') + 1609372800/24/60/60/1000;
SELECT count(*), gender FROM PERSON where ceiling(salary/1000.0)*1000 group by gender; SELECT count(*),gender FROM PERSON 其中天花板(salary/1000.0)*1000 按性别分组;
Likely, the problem is the fiter on the dates.问题很可能出在日期上的合适人选。 You seem to assume that 946684800
is a unix epoch in milliseconds , while it looks like it is expressed in seconds.你似乎假设946684800
是一个以毫秒为单位的unix时代,而它看起来是以秒为单位表示的。
Consider:考虑:
alter session set nls_date_format = 'yyyy-mm-dd hh24:mi:ss';
-- your expression
select to_date('19700101', 'YYYYMMDD') + 946684800/24/60/60/1000 dt from dual
| DT |
| :------------------ |
| 1970-01-11 22:58:05 |
-- isn't this better?
select to_date('19700101', 'YYYYMMDD') + 946684800/24/60/60 dt from dual
| DT |
| :------------------ |
| 2000-01-01 00:00:00 |
I would also recommend giving a literal number to the filer on salary rather than a string (unexpected things happen when you compare values of different datatypes).我还建议给文件管理器一个文字数字而不是一个字符串(当你比较不同数据类型的值时会发生意想不到的事情)。 Finally, date literals should be preferred to to_date()
whenever possible.最后,只要有可能,日期文字应该优先于to_date()
。
You could phrase the query as:您可以将查询表述为:
select *
from person
where
gender = 'female'
and salary > 5000.50
and birth_date between date '1970-01-01' + 946684800/24/60/60
and date '1970-01-01' + 1609372800/24/60/60;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.