对pl/sql 语句的优化(下集)
上集中
//////////////////////////////////////////////////
select n5001 门店,n5002 部门,n5004 小分类,n5019 商品编码,c01d21 商品名称,
nvl(xse,0)-nvl(dzxs,0) 销售,
mle 毛利,
nvl(xl,0)-nvl(dzsl,0) 销量
from
(select n5001,n5002,n5004,n5019,sum(n5011) xse,sum(n5016) mle,sum(n5023) xl
from n50
where n5010 between to_date('20100401','yyyymmdd') and to_date('20100430','yyyymmdd')
group by n5001,n5002,n5004,n5019),
(select g08,g09,g02,sum(g03*g07) dzxs,sum(G03) dzsl from batchgoods
where g04 between to_date('20100401','yyyymmdd') and to_date('20100430','yyyymmdd')
group by g08,g09,g02),c01d
where n5001=g08(+)
and n5019=g02(+)
and n5001=c01d00(+)
and n5019=c01d01(+)
SELECT STATEMENT, GOAL = CHOOSE Cost=10163 Cardinality=30832 Bytes=3730672
MERGE JOIN OUTER Cost=10163 Cardinality=30832 Bytes=3730672
MERGE JOIN OUTER Cost=1794 Cardinality=30832 Bytes=2959872
SORT JOIN Cost=1743 Cardinality=30832 Bytes=1880752
VIEW Object owner=FZDC Cost=1098 Cardinality=30832 Bytes=1880752
SORT GROUP BY Cost=1098 Cardinality=30832 Bytes=1171616
TABLE ACCESS BY INDEX ROWID Object owner=FZDC Object name=N50 Cost=668 Cardinality=30832 Bytes=1171616
INDEX RANGE SCAN Object owner=FZDC&n
相关文档:
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_convert]') and xtype in (N'FN', N'IF', N'TF'))&n ......
分布式查询
OPENROWSET
从Excel取数据
SELECT * from OPENROWSET('Microsoft.Jet.OLEDB.4.0','Excel 8.0;Database=d:\1.xls',[Sheet1$])
从Oracle取数据
SELECT * from OPENROWSET('MSDAORA.1','NetServiceName ......
1.修改列
EXEC sp_rename 'TableName.ColumnName','NewColumName'
2.增加列
ALTER TABLE TableName ADD ColumnName int --Type In Here
3.删除列
ALTER TABLE TableName DROP Column ColumnName ......
Access 的 SQL 中,计算相应编号的记录之间 加 减 的查询命令
例如 计算ID为 6 的 合计 减去 ID 为 2、3、4 以及加上 ID 为 5 的合计
SELECT SUM(R) AS 结果
from
(
SELECT 合计 AS R from T1 WHERE (ID = 6) UNION
SELECT -合计 AS R from T1 WHERE (ID = 2) UNION
SELECT -合计 AS R f ......
1.
SQL> desc gjh_a05 ;
Name Type Nullable Default Comments
----- ------------- -------- ------- --------
A0500 VARCHAR2(2) Y &nbs ......