mysql中datetime比較大小問題


select sum(studychj) as tofflinejz from afterline where checkflag=1 and studytype=1 and studybegin>='2010-01-01 00:00:00' and studyend<='2010-12-01 00:00:00' and username='01009' 這么寫不報錯,但得出結果不准確 方法一: 你也可以: select * from t1 where unix_timestamp(time1) > unix_timestamp('2011-03-03 17:39:05') and unix_timestamp(time1) < unix_ timestamp('2011-03-03 17:39:52'); 就是用unix_timestamp函數,將字符型的時間,轉成unix時間戳。個人覺得這樣比較更踏實點兒。 方法二: time1 between '2011-03-03 17:39:05' and '2011-03-03 17:39:52'; 方法三: 可以講datetime類型轉換成date類型再進行比較 例如:convert(date,表名.datetime列名) >= convert(date,表名.datetime列名) 三種方法待求證,總之是不要用字符串這么直接比


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM