重慶分公司,新征程啟航
為企業提供網站建設、域名注冊、服務器等服務
為企業提供網站建設、域名注冊、服務器等服務
select * from 表
成都網絡公司-成都網站建設公司成都創新互聯公司十載經驗成就非凡,專業從事成都網站建設、網站建設,成都網頁設計,成都網頁制作,軟文發布平臺,1元廣告等。十載來已成功提供全面的成都網站建設方案,打造行業特色的成都網站建設案例,建站熱線:18980820575,我們期待您的來電!
where to_char(TempDate,'hh24:mi') between '00:00' and '11:00'
我在PLSQL里面必須這樣寫,只寫小時會僅限制到最后那天的11點。
寫法有很多種,例如下面的:
方法一:select * from dual where time between to_date('2012-06-18 00:00:00','yyyy-mm-dd hh24:mi:ss') and to_date('2012-06-18 23:59:59','yyyy-mm-dd hh24:mi:ss');
方法二:select * from dual where to_char(time,'yyyy-mm-dd')='2012-06-18';
方法三:select * from dual where trunc(time)=to_date('2012-06-18','yyyy-mm-dd');
當然樓主也可以按上面的先轉換下日期的顯示格式再查詢撒,都可以的,呵呵!!!
建表和插入數據?
create?table?table_a(?t1?date,?t2?date);
insert?into?table_a?values(to_date('20140501','yyyymmdd')?,to_date('20140503','yyyymmdd'));
insert?into?table_a?values(to_date('20140508','yyyymmdd')?,to_date('20140509','yyyymmdd'));
create?table?table_b(t?date,id?int)
insert?into?table_b?values(to_date('20140501','yyyymmdd'),1);
insert?into?table_b?values(to_date('20140502','yyyymmdd'),2);
insert?into?table_b?values(to_date('20140503','yyyymmdd'),3);
insert?into?table_b?values(to_date('20140504','yyyymmdd'),4);
insert?into?table_b?values(to_date('20140505','yyyymmdd'),5);
insert?into?table_b?values(to_date('20140506','yyyymmdd'),6);
insert?into?table_b?values(to_date('20140507','yyyymmdd'),7);
insert?into?table_b?values(to_date('20140508','yyyymmdd'),8);
insert?into?table_b?values(to_date('20140509','yyyymmdd'),9);
insert?into?table_b?values(to_date('20140510','yyyymmdd'),10);
insert?into?table_b?values(to_date('20140511','yyyymmdd'),11);
查詢語句?
select?*?from?table_b?where?t?not?in(
select?distinct?b.t?from?table_b?b,table_a?a?where?b.t??between?a.t1?and?a.t2)
第一種:直接用語句
date1與date2是字符串
SQL.Tet:='select * from table where 字段 between '+Quotedstr(date1)+' and '+Quotedstr(date2);
date1與date2是日期
SQL.Tet:='select * from table where 字段 between '+Quotedstr(DateTimeToStr(date1))+' and '+Quotedstr(DateTimeToStr(date2));
第二種:用參數形式:
SQL.Tet:='select * from table where 字段 between :d1 and :d2';
Parameters.ParamByName('d1').Value:=date1;
Parameters.ParamByName('d2').Value:=date2;
select to_char(sysdate-1.'dd') from dual);
1后邊是逗號,
看你的語句是取一個日期,干嘛要用IN呢,IN很影響執行效率,特別是表中數據比較大的時候,我覺得用這個就可以:
select to_char(edit_time,'dd') as newtime from table where newtime=to_char(sysdate-1,'dd')
你查到的是2022-06-21的數據,那么只需要再加一天2021-06-21不就可以了,在時間的地方加一個or,用擴考括起來就可以了。然后在group by和orderby的時候,加一個出院時間就OK了。
不過現在這個時間不能直接用,因為你的出院時間是包括時分秒的,這里你需要截取到日,不然group by和orderby的時候的時候也會按照時分秒去分組排序的。
至于出來以后的顯示結果什么樣,要看你要的是什么樣子,然后再用其他分組調整函數(比如cube等)想辦法調整最后的順序。