Çë½ÌsqlÓï¾ä¡£ - Oracle / ¿ª·¢
ÎÒÓÐÒ»¸ö±í£¬½á¹¹ÊÇÕâÑù¡£
ת³ö µ¥Î» תÈ뵥λ ±ÊÊý ½ð¶î
date(Ö÷) outid(Ö÷) inid(Ö÷) num amt
2009 1 2 1 500 Ϊ 1 µ¥Î» ÔÚ2009Äê¸ø 2 ת³ö 1 ±Ê 500Ôª
2009 1 3 1 100 Ϊ 1 µ¥Î» ÔÚ2009Äê¸ø 3 ת³ö 1 ±Ê 100Ôª
2009 1 4 3 200 Ϊ 1 µ¥Î» ÔÚ2009Äê¸ø 4 ת³ö 3 ±Ê 200Ôª
2009 2 1 2 100 Ϊ 2 µ¥Î» ÔÚ2009Äê¸ø 1 ת³ö 2 ±Ê 100Ôª
2009 4 1 1 100 Ϊ 4 µ¥Î» ÔÚ2009Äê¸ø 1 ת³ö 1 ±Ê 100Ôª
2009 3 1 2 100 Ϊ 3 µ¥Î» ÔÚ2009Äê¸ø 1 ת³ö 2 ±Ê 100Ôª
ÎÒÐèÒª²é³ö½á¹ûÈçÏÂ,²éѯ³ö2£¬3£¬4µ¥Î»¸ø1ת³öµÄ£¬ºÍÓÉ1תÈëµÄ£º
µ¥Î» ת³ö±ÊÊý ת³ö½ð¶î תÈë±ÊÊý ת³ö½ð¶î
id date outnum outamt innum inamt
2 2009 2 200 1 500
3 2009 2 100 1 100
4 2009 1 100 3 200
ÇëÎÊsqlÔõôд£¿
¶àл¡£¡£¡£¡£
select outid as id,date,sum(num),sum(amt)
from tb
where outid in (2,3,4) and inid =1]
group by outid,date
¿´ÔÎÁË,Êý¾ÝÊDz»ÊDz»¶Ô°¡
Ó¦¸ÃÊÇת¸ø1µÄºÍÓÉ1ת³öµÄ°É
Êý¾Ý²»¶Ô°¡
SQL code
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
Ïà¹ØÎÊ´ð£º
±íÈçÏÂ
½ÌÊÒID ×ùλÊý ¿ªÊ¼Ê±¼ä ½áÊøÊ±¼ä 2009Äê1ÔÂ1ÈÕ 2009Äê1ÔÂ2ÈÕ 2009Äê1ÔÂ3ÈÕ
101 50 08£º00 08£º30 30 40 50
101 50 09£º00 ......
select convert(varchar(50),cast(convert(numeric(18,2),1275674000000/100000000)as real))+'ÒÚ'
select cast(convert(numeric(18,2),1275674000000/100000000)as real)
ΪʲôÉÏÒ»¸öÓÃvarcharת»»ºó¾ÍÖ»±£ÁôÁËÒ ......
±¾À´ÒªÐ´¸öupdateÓï¾ä
update table_a A
set A.flag=1
where A.id in (select B.id from table_b B)
½á¹ûÎóд³É
update table_a A
set A.flag=1
where ......
³¡¾°ÈçÏ£º
¿Í»§°Ñ±¸·ÝºÃµÄÊý¾Ý¿â£¬·¢¸øÎÒ£¬ÎÒÔÚ±¾»ú»¹Ôºó£¬ÔËÐÐдºÃµÄ´æ´¢¹ý³Ì£¬±È½Ï¿ì£¬²¢ÇÒÔÚʵʩÄDZßÔËÐÐͬÑù±È½Ï¿ì¡£µ«Êǵ±ÊµÊ©ÔÚ¿Í»§ÄDZßÔËÐеÄʱºòËٶȾͷdz£µÄÂý£¬Ê±¼ä³¬³öÁ˳ÌÐòµÄʱ¼äÏÞÖÆ¡£Ô¶³ÌÔÚ¿Í»§ÄÇ ......
private static final String URL = "jdbc:oracle:thin:@localhost:1521:orcl";
private static final String USERNAME = "sys";
private static final String PASSWORD = "s ......