SQL DATETIME×ֶαȽÏ
±ÈÈçÓиö±íÆäÖÐÓÐ3¸ödatetime×ֶΣ¬Ò»°ãÀ´ËµÆäÖÐÓиödatetime×ֶεÄÖµ»á±ÈÆäËû2¸ö´ó£¨Ð޸ĺóÈÕÆÚ£©£¬ÄÇÔõôÕÒ³öÕâÌõ¼Ç¼£¿
來數據說Ã÷°É
...........
select * from TB where dt1>dt2 and dt1>dt3
union all
select * from TB where dt2>dt1 and dt2>dt3
union all
select * from TB where dt3>dt1 and dt3>dt1
±È½ÏÁ½¸öÈÕÆÚµÄ²î£º
ÓÃ datediff()
SQL code:
select * from TB where dt1>dt2 and dt1>dt3
union all
select * from TB where dt2>dt1 and dt2>dt3
union all
select * from TB where dt3>dt1 and dt3>dt1
ÕÒ³ö¼Ç¼»¹ÊÇÕÒ³ö×Ö¶Î?
DATEDIFF ( datepart , startdate , enddate )
SQL code:
create table #test
(dt1 datetime,
dt2 datetime,
dt3 datetime)
insert #test
select '20100110','20091221','20121212' union all
select '20091221','20121212','20100110' union all
select '20121212','20091221','20100110'
select
case when dt1>dt2 and dt1>dt3 then dt1 else null end,
case when dt2>dt1 and dt2>dt3 then dt2 else null end,
case when dt3>dt2 and dt3>dt1 then dt3 else null end
from #test
Ïà¹ØÎÊ´ð£º
ÎÒÓжà¸ö±íA B C ½á¹¹ÊÇÒ»ÑùµÄ£¬¶¼ÓÐ2¸ö×Ö¶ÎnameºÍcontent,ÎÒÒªËÑË÷ËùÒÔ±íËùÓÐ×Ö¶ÎÖаüº¬¡°Öйú¡±µÄÄÚÈÝ Õâ¸öSQLÓï¾äÔõôд
ÈçºÎ½«¶à¸ö±íµÄ²éѯ½á¹ûÁ¬³ÉÒ»¸ö±í Õâ¸öSQLÓï¾äÔõôд ±íµÄ½á¹¹ÊÇÒ»ÑùµÄ
ÀýÈç£ ......
³¡¾°ÈçÏ£º
¿Í»§°Ñ±¸·ÝºÃµÄÊý¾Ý¿â£¬·¢¸øÎÒ£¬ÎÒÔÚ±¾»ú»¹Ôºó£¬ÔËÐÐдºÃµÄ´æ´¢¹ý³Ì£¬±È½Ï¿ì£¬²¢ÇÒÔÚʵʩÄDZßÔËÐÐͬÑù±È½Ï¿ì¡£µ«Êǵ±ÊµÊ©ÔÚ¿Í»§ÄDZßÔËÐеÄʱºòËٶȾͷdz£µÄÂý£¬Ê±¼ä³¬³öÁ˳ÌÐòµÄʱ¼äÏÞÖÆ¡£Ô¶³ÌÔÚ¿Í»§ÄÇ ......
СµÜ£¬×î½üҪתÐÐÈ¥×öoracle¿ª·¢ÁË£¬ÓÉÓÚ´óѧ±Ïҵʱ£¬×ßÁ˸öÍä·£¬ÏÖÔÚºÜСÐÄ£¬ÎÊÏ£¬×öPL/SQLÓÐûÓÐǰ;£¿£¿£¿
µ±È»ÎÒ˵µÄÕâ¸öǰ;ÊÇÖ¸ ÒÔºóÒªÌø²Û£¬Êг¡¶ÔÕâÑùµÄÈ˲ŵÄÐèÇóÁ¿´ó²»´ó£¿£¿
3q ÄÇ¿´À´»¹Ö»ÄÜÏȽӴ ......
ÏÖÔÚÓÐÁ½ÕÅ±í£ºÎÄÕÂÖ÷±íA(articleId,articleTitle)£¬ÎÄÕÂÆÀÂÛ±íB(commentId,articleId,commentTitle)
ÏÖÔÚÎÒÏëʵÏÖÕâÑùµÄ¹¦ÄÜ£ºÁгöÎÄÕÂÁÐ±í£¬ÆäÖÐÿƪÎÄÕ±êÌâÏÂÃæÁгö´ËÎÄÕµÄǰ2¸öÎÄÕÂÆÀÂÛ£¬ÇëÎÊsqlÓï¾äÔõôд°¡ ......