查詢篇-按收取學費的比例給老師發工資
2013年07月30日 09:03
點擊率:11618
|
之前的文章講過老師薪金計算的三種基本方法: http://www.hbpufeike.com/docshow_c21_158.aspx其中第三種“按上課學員實際消耗的課時產出計算老師提成。”精度非常高,消耗資源大,并且要特殊配置。今天我們講的也是第三種,但是參數選擇不同所以實現起來比較簡單。單價參考的是學員最后一次交費時的課時單價,可以滿足大部分學校的需求。 主查詢: Select LessonDegree.TeacherID as 工號, Users.TrueName as 姓名, sum(Attend.Lessons * (BillItem.UnitPrice + BillItem.Favorable / BillItem.Amount)) as 金額, sum(Attend.Lessons * (BillItem.UnitPrice + BillItem.Favorable / BillItem.Amount)) * 0.2 as 提成金額, LessonDegree.TeacherID as ShowKey from Attend,LessonDegree,StuClass,BillItem,Users where Attend.LessonDegreeID = LessonDegree.LessonDegreeID and Attend.StuClassID = StuClass.StuClassID and StuClass.LastBillItemID = BillItem.BillItemID and LessonDegree.TeacherID = Users.UserID and LessonDegree.StartDate >= {@StartDate:開始日期} and LessonDegree.StartDate <= {@EndDate:結束日期} group by LessonDegree.TeacherID,Users.TrueName
子查詢: Select StuClass.StudentID as 學號, StuClass.StudentName as 姓名, StuClass.ClassID as 班號, StuClass.ClassName as 班名, Attend.Lessons as 課時, BillItem.UnitPrice as 單價, LessonDegree.StartDate as 日期 from Attend,LessonDegree,StuClass,BillItem where Attend.LessonDegreeID = LessonDegree.LessonDegreeID and Attend.StuClassID = StuClass.StuClassID and StuClass.LastBillItemID = BillItem.BillItemID and Attend.Lessons > 0 and LessonDegree.StartDate >= {@StartDate} and LessonDegree.StartDate <= {@EndDate} and LessonDegree.TeacherID = {@ShowKey} 統計某段時間學員所上課時的價值有一定的難度,因為優惠的客觀存在,并且某段時間內存在學員多次購買課時、并且單價不同的問題。上面這段代碼選擇的是學員最后一次購買課時的單價做為標準進行構造的, StuClass.LastBillItemID = BillItem.BillItemID 從這句條件語法可以看出來。 (BillItem.UnitPrice + BillItem.Favorable / BillItem.Amount)這段代碼用于計算課時實際單價(去除優惠后),因為優惠金額在系統里一直使用負數表達,所以這里用原單價+優惠單價=實際單價。 sum(Attend.Lessons * (BillItem.UnitPrice + BillItem.Favorable / BillItem.Amount))這段代碼表示學員上課課時數 X 最后一次購買課時的單價 = 實際課時產值。 sum(Attend.Lessons * (BillItem.UnitPrice + BillItem.Favorable / BillItem.Amount)) * 0.2 as 提成金額,這段代碼表示課時產出的20%用于老師的提成。根據學校的實際情況修改這里的0.2來調節提成比例。 (把以上代碼粘貼到《麥田培訓學校管理軟件》查詢管理里,可直接使用)
|