SELECT COUNT(*) AS 总条数, SUM(JQ) AS 金额,COUNT(PZ) AS 品种1,COUNT(P,2) AS 品种2, COUNT(PZ3) AS 品种3 FROM 表1
GROUP BY ?????
我就想要个5个总数,有简便方法吗?
没有太复杂吧,像你这样调用系统函数可以啊。
TOP(5) 就好了!
create table _20130403_t1 (id int identity(1,1),jq decimal(20,2),pz varchar(20),pz2 varchar(20),pz3 varchar(20)) select * from _20130403_t1 insert into _20130403_t1 values(2,'p1','p11','p111') insert into _20130403_t1 values(10,'p1','p11','p112') insert into _20130403_t1 values(3,'p1','p12','p121') insert into _20130403_t1 values(9,'p1','p12','p122') insert into _20130403_t1 values(4,'p2','p21','p211') insert into _20130403_t1 values(8,'p2','p21','p212') insert into _20130403_t1 values(5,'p2','p22','p221') insert into _20130403_t1 values(7,'p2','p22','p222') select count(1),sum(jq),count(distinct pz),count(distinct pz2),count(distinct pz3) from _20130403_t1