Ö÷±í
µ¥ºÅ ÈÕÆÚ
001 2009-01-01
002 2009-01-02
001J1 2009-01-03
001J2 2009-01-03
002J1 2009-01-03
002J2 2009-01-08
002J3 2009-01-09
Ã÷ϸ±í
µ¥ºÅ »õÎïÃû³Æ
001 ´óÃ×
001 Âܲ·
002 Ïã¹½
002 »Æ¶¹
001J1 ÃæÌõ
001J1 °×²Ë
001J2 ° ......
ÎÒÒª½«Ò»¸öÕâÑùµÄ±í
ÓÃSQL²éѯ³öÀ´ºóÒªÊÇÕâÑùµÄ,
ÇëÎÊÔõôдSQLÓï¾ä °¡
1¡¢Íâ¡¢ÄÚ¡£ÖÐÔõôµÃµ½µÄ
select a,b,c,d,e,f,g,h,i=case when Ìõ¼þ then 'Íâ' when Ìõ¼þ2 then 'ÄÚ' when Ìõ¼þ3 then 'ÖÐ' end
from tb
ÁÖºìÍâF£¬G£¬HµÄÊý¾ÝʱÔõôµÃµ½µÄ£¿
ÄÚ,Íâ,ÖÐ,ÊÇÌõ¼þ,¸ù¾ÝÄÚ,Íâ,ÖвéѯµÃµ½µÚ¶þÕÅÄÇÑùµÄ±í
Á¬½Ó,Í ......
¶©µ¥»ù´¡±í
PO_HEAD_TBL
×Ö¶Î
PO_NO SUM_PRICE
0001 20.55
¶©µ¥ÏêϸÐÅÏ¢±í
PO_LINE_TBL
ID PO_NO UNIT_PRICE
1 0001 10.55
2 0001 5.0
3 0001 5.0
oracleÊý¾Ý¿â
Á½¸ö±íµÄ¹ØÁª×Ö¶ÎÊÇPO_NO
¶©µ¥»ù´¡±íÖÐµÄ SUM_PRICE ×Ö¶Î ......
ÎÒÒª´´½¨Ò»¸öÁÙʱ±í±£´æÊý¾Ý
·½·¨Ò»£º
declare @sql varchar(1000)
set @sql = 'select identity(int,1,1) as tbId,* into #tb1 from table1 where 1=0'
exec(@sql)
select * from #tb1
drop table #tb1
·½·¨¶þ£º
select identity(int,1,1) as tbId,* into #tb2 from table1 where 1=0
select * from #tb2
drop t ......
SQL code:
create table order1 (ʱ¼ä varchar(30) primary key not NULL ,×èÖµ numeric(5,3) , ¹¦ÂÊ numeric(5,3))
INSERT INTO order1(ʱ¼ä,×èÖµ,¹¦ÂÊ )VALUES (convert(varchar,getdate(),21),123,333)
±¾ÈËÏëÔڸñíµÄʱ¼ä×Ö¶ÎÉϼÓÒ»¸ö¾Û¼¯Ë÷Òý£¬ÒÔÄêÔÂÈÕСʱΪµ¥Î»£¬Ôõôд£¿
SQL code:
create table ......
±ít1¡¢t2Ïàͬ
µ±t1ÖУ¬A¡¢BÁ½¸ö×Ö¶ÎÏàͬʱ£¬½«×Ö¶ÎCÇóºÍºó²åÈëµ½t2ÖÐ
ÔÚt1ÖУº
A B C
a1 b1 1
a1 b1 2
a1 b1 3
a2 b2 1
a2 b2 2
ÐèÒªÔÚt2Öеõ½
a1 b1 6
a2 b2 3
SQL code:
insert t2
selct A,B,sum(C) C from t1 group by A,B
SQL code:
insert c select a,b,isnull(c, ......