hi have the following sql which works ok
i need to sum stdtime to give a total for each group
that is a sum for
mot.bayid = 1 AND mot.baytypeid =1
and a sum for
mot.bayid = 2 AND mot.baytypeid =1
etc...
i also need a total sum for the above sums?
i need to sum stdtime to give a total for each group
that is a sum for
mot.bayid = 1 AND mot.baytypeid =1
and a sum for
mot.bayid = 2 AND mot.baytypeid =1
etc...
i also need a total sum for the above sums?
Code:
motsql1 = "SELECT mot.mott, car.carid, car.reg, book.bookid, book.bookdate, book.waittick, cus.fname, cus.lname, cus.pcode, cus.cusid, mot.bayid, mot.motid, mot.dayid, mot.baytypeid, sum(stdwork.stdtime) AS stdtime, "_
& "FROM mottimes AS mot "_
& "LEFT JOIN book ON mot.motid = book.slotid "_
& "AND book.bookdate = "&[datesql] _
& " LEFT JOIN car ON car.carid = book.carid "_
& "LEFT JOIN cus ON cus.cusid = car.cusid "_
& "LEFT JOIN stdworklink ON stdworklink.bookid = book.bookid "_
& "LEFT JOIN stdwork ON stdwork.stdworkid = stdworklink.stdworkid "_
& "WHERE mot.dayid ="&[motdaysql] _
& " AND ((mot.bayid = 1 AND mot.baytypeid =1) or "_
& "(mot.bayid = 2 AND mot.baytypeid =1) or "_
& "(mot.bayid = 1 AND mot.baytypeid =2) or "_
& "(mot.bayid = 2 AND mot.baytypeid =2) or "_
& "(mot.bayid = 3 AND mot.baytypeid =3)) "_
& "GROUP BY mot.motid, mot.mott, mot.bayid, mot.baytypeid "_
& "ORDER BY mot.motid"