日期:2014-05-18 浏览次数:20561 次
IF EXISTS (SELECT 1 FROM SYSOBJECTS WHERE name = 'A') BEGIN DROP TABLE A END GO CREATE TABLE A ( A_ID INT, A_数值 INT, A_条件 VARCHAR(100) ) GO IF EXISTS (SELECT 1 FROM SYSOBJECTS WHERE name = 'B') BEGIN DROP TABLE B END GO CREATE TABLE B ( B_ID INT, B_A权值 INT, A_ID INT, B_条件 VARCHAR(100) ) GO INSERT INTO A SELECT 1,4,'haha' UNION SELECT 2,4,'hihi' UNION SELECT 3,2,'hoho' INSERT INTO B SELECT 1,40,1,'haha' UNION SELECT 2,60,2,'hihi' UNION SELECT 3,20,3,'hoho' SELECT SUM(B_A权值 * A_数值)/SUM(A_数值) AS Avg FROM A , B WHERE A.A_ID = B.A_ID Avg 44