[英]Oracle query for finding the records
我沒有從以下 2 個查詢中得到任何結果。 如果此查詢有任何問題,請告訴我。
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 其中天花板(salary/1000.0)*1000 按性別分組;
問題很可能出在日期上的合適人選。 你似乎假設946684800
是一個以毫秒為單位的unix時代,而它看起來是以秒為單位表示的。
考慮:
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 |
我還建議給文件管理器一個文字數字而不是一個字符串(當你比較不同數據類型的值時會發生意想不到的事情)。 最后,只要有可能,日期文字應該優先於to_date()
。
您可以將查詢表述為:
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.