Çó¸ösqlÓï¾ä£¬¹À¼ÆÓеãÄÑŶ2 Çëacmin_CHM½øÀ´
Èç¹ûo±íÀïÒ²ÓÐ f g ÏÔʾ½á¹ûµÄʱºò£¬Èç¹û st±íÀïûÓÐÊý¾Ý£¬¾ÍÏÔʾ o±íµÄf g£¬Èç¹ûstÀïÄÜÏÔʾ f g µÄÖµ ¾Í ²»ÏÔʾo±íµÄf g Óï¾ä¸ÃÔõÃ´Ð´ÄØ¡£
£¨ÖØ¿ªÒ»Ìù£©ACMAIN_CHM Çë´ð£¬ÎÒÑ¡ÔñÓÃÄãµÄÓï¾ä¼òµ¥ºÃÀí½â£¬µ±È»ÆäËûµÄÒ²²»´í¡£Ð»Ð»´ó¼Ò
SQL code:
select
o.*,
case when st.f is null then o.f else st.f end as f,
case when st.g is null then o.g else st.g end as g
from
o
left join
(
select
mid,
max(if(type='f',value,0)) as f,
max(if(type='g',value,0)) as g
from
st
where
not exists(select 1 from st s where s.mid=st.mid and s.type=st.type and s.time>st.time)
group by mid
) as st
on o.mid=st.mid
¼Ó¸öIFNULLº¯Êý¡£
SQL code:
select o.*,
IFNULL((select `value` from st where mid=o.mid and type='f' order by `time` desc limit 1),0) as f,
IFNULL((select `value` from st where mid=o.mid and type='g' order by `time` desc limit 1),0) as g
from o
josy
ÄúµÄÓï¾äÀïµÄ select 1 ²»ÖªµÀÊDz»ÊÇÓÐÎÊÌâ
acmain_chm Õâ¸öÒâ˼²»¶Ô£¬µ± stÀïÄÜselect³öÖµµÄʱºò¾ÍÏÔʾ stÀïµÄÖµ£¬µ«ÊÇûÓУ¬¾ÍÏÔʾ oµÄ f gµÄÖµ¡£
Ó¦¸Ã²»»áÓÐÎÊÌ⣬±¨´í»¹ÊÇÊý¾Ý²»¶Ô£¿
ÁíÍ⣬»¹¿ÉÒÔÊÔÊÔÏÂÃæÕâ¸ö£º
SQL code
Code highlighting produced by Actipro Co
Ïà¹ØÎÊ´ð£º
ÎÒÓжà¸ö±íA B C ½á¹¹ÊÇÒ»ÑùµÄ£¬¶¼ÓÐ2¸ö×Ö¶ÎnameºÍcontent,ÎÒÒªËÑË÷ËùÒÔ±íËùÓÐ×Ö¶ÎÖаüº¬¡°Öйú¡±µÄÄÚÈÝ Õâ¸öSQLÓï¾äÔõôд
ÈçºÎ½«¶à¸ö±íµÄ²éѯ½á¹ûÁ¬³ÉÒ»¸ö±í Õâ¸öSQLÓï¾äÔõôд ±íµÄ½á¹¹ÊÇÒ»ÑùµÄ
ÀýÈç£ ......
ÒòΪƽʱÕâÖÖ²Ù×÷±È½Ï¶à£¬Ö±½ÓÔÚÊý¾Ý¿âÉÏÊÖ¶¯ÉèÖÃΣÏÕÐԽϴó£¬ËùÒÔÏëÓÃSQLÓï¾äʵÏÖ¡£
ÔÚÍøÉÏʵÔÚËѲ»µ½½á¹û£¬ÕâÀï¸ßÊֶ࣬ϣÍûÄܵõ½´ð°¸¡£
лл¡£
ÄãÏëÔõ麼設ÖÃ?
SQL code:
--´´½¨²âÊÔ±í
......
select convert(varchar(50),cast(convert(numeric(18,2),1275674000000/100000000)as real))+'ÒÚ'
select cast(convert(numeric(18,2),1275674000000/100000000)as real)
ΪʲôÉÏÒ»¸öÓÃvarcharת»»ºó¾ÍÖ»±£ÁôÁËÒ ......
C# code:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.We ......