select left(b.transdate,10), c.goodsname, sum(a.quantity), sum(a.salesvalue) from demo.transactiondetails a join demo.transactionhead b on (a.transactionid = b.transactionid) join demo.goodsmaster c on (a.itemnumber= c.itemnumber) group by left(b.transdate,10),c.goodsname order by left(b.transdate,10),c.goodsname;
select sum(quantity), sum(salesvalue) from demo.transactiondetails;
AVG()、MAX()、MIN()
1.AVG()
1 2 3 4 5 6 7 8 9 10 11 12 13
select left(a.transdate,10), c.goodsname, avg(b.quantity), avg(b.salesvalue) from demo.transactionhead a join demo.transactiondetails b on (a.transactionid = b.transactionid) join demo.goodsmaster c on(b.itemnumber = c.itemnumber) group by left(a.transdate,10),c.goodsname order by left(a.transdate,10),c.goodsname;
2.MAX()、MIN()
1 2 3 4 5 6 7 8 9 10 11 12
select left(a.transdate,10), MAX(b.quantity), MAX(b.salesvalue) from demo.transactionhead a join demo.transactiondetails b on(a.transactionid = b.transactionid) join demo.goodsmaster c on (b.itemnumber = c.itemnumber) group by left(a.transdate,10) order by left(a.transdate,10);
select left (a.transdate,10),c.goodsname,count(*) from demo.transactionhead a join demo.transactiondetails b on(a.transactionid = b.transactionid) join demo.goodsmaster c on (b.itemnumber = c.itemnumber) group by left(a.transdate,10),c.goodsname order by left(a.transdate,10),c.goodsname;