日期:2014-05-17 浏览次数:20432 次
create table zsy
(商品 varchar(5), 价钱 int)
insert into zsy
select 'A1', 50 union all
select 'A2', 60 union all
select 'A3', 55 union all
select 'A1', 90 union all
select 'A2', 70
select 商品,
count(1) '数量',
(select sum(价钱) from zsy)-sum(价钱) '价钱'
from zsy
group by 商品
/*
商品 数量 价钱
----- ----------- -----------
A1 2 185
A2 2 195
A3 1 270
(3 row(s) affected)
*/
IF OBJECT_ID('T_CSDN_ONE') IS NOT NULL
BEGIN
DROP TABLE T_CSDN_ONE
END
CREATE TABLE T_CSDN_ONE
(
SP VARCHAR(20),
JQ DECIMAL(12,2)
)
INSERT INTO T_CSDN_ONE
(
SP,
JQ
)
SELECT 'A1',50
UNION ALL
SELECT 'A2',60
UNION ALL
SELECT 'A3',55
UNION ALL
SELECT 'A1',90
UNION ALL
SELECT 'A2',70
SELECT
(SELECT SUM(JQ) FROM T_CSDN_ONE)-SUM(JQ)
FROM T_CSDN_ONE
GROUP BY SP