我需要所有的代碼,其中curdate
是今天... curdate
是timestamp
類型。 當然我在谷歌搜索這個,但我想我已經使用了錯誤的關鍵字。SQL今天的「Where」語法
select * from ftt.element fee, ftt.plan p
where p.id=ftt.p_id and curdate ???
order by p_id, curdate desc;
您能否提供我?
我需要所有的代碼,其中curdate
是今天... curdate
是timestamp
類型。 當然我在谷歌搜索這個,但我想我已經使用了錯誤的關鍵字。SQL今天的「Where」語法
select * from ftt.element fee, ftt.plan p
where p.id=ftt.p_id and curdate ???
order by p_id, curdate desc;
您能否提供我?
SYSDATE
返回當前datea 和時間甲骨文。 A DATE
列也包含Oracle中的時間部分 - 一個TIMESTAMP
列。
爲了檢查「今天」你必須在兩個值中刪除部分時間:
select *
from ftt.element fee
join ftt.plan p on p.id=ftt.p_id
where trunc(curdate) = trunc(sysdate)
order by p_id, curdate desc;
你也應該習慣使用明確JOIN
s,而不是隱含加入WHERE
子句。
如果您需要照顧不同的時區(例如,因爲curdate
是timestamp with time zone
),那麼你可能想使用CURRENT_TIMESTAMP
(包括時區),而不是SYSDATE
正是我正在尋找!非常感謝 –
有基本的日常功能。這裏有雲一對夫婦:
getDate()
Now()
不知道你的DBMS我不能說哪個特別將工作
無論你已經完成的工作是非常麻煩!!!!我從上面的查詢中做出的是你正在試圖加入2個表格。 首先要加入2個表:
Select * from table1 join table2 on table1.id = table2.id;
我們包括在該查詢concate這上面的查詢之後的任何條件:
Select * from table1 join table2 on table1.id = table2.id where curdate = date;
這裏限定日期= CURDATE();在啓動查詢之前。 希望它能幫助你。
這個答案與a_horses_with_no_name的答案非常相似。區別在於它執行速度更快。在比較之前對列進行計算會降低性能。
select *
from ftt.element fee
join ftt.plan p on p.id=ftt.p_id
where curdate >= trunc(sysdate)
and curdate < trunc(sysdate + 1)
order by p_id, curdate desc;
你總是可以在'trunc(curdate)' –
@a_horse_with_no_name上創建一個索引製作索引來彌補糟糕的代碼,對不起,說的是不好的做法 –
對不起,說:) - 但我不認爲這個「壞代碼「。這是一個有效的條件。 –
這是在PHP中完成的嗎? –
您使用的是什麼RDBMS? MySQL的? Postgres的?甲骨文?當前日期的功能可能在每個日期中有所不同。 –
不,這只是一個Oracle的聲明... –