我有两个表。在sql中选择每个组的第一行
1-> SM_Employee
(1) employeeid (2) roleid (3) storeid
2-> SM_SalesRepWorkflow
(1) workflowid (2) Salesrepid foreign key to employeeid (3) QuantityAssigned (4) QuantityLeft (5) month (6) year
通过这些表我需要选择从SM_SalesRepWorkflow顺序每SalesRep的详细的第一行通过SalesRepId为CurrentMonth和CurrentYear。
例
Workflowid SalesRepId QuantityAssigned QuantityLeft月年
WF_101:EMP_101:100:90:月:2013
WF_101:EMP_102:100:100:月:2013
WF_101:EMP_103 :100:80:May:2013
WF_102:EMP_101:100:70:May:2013
所以导致我想要的是
WF_101:EMP_101:100:90:五月:2013
WF_101:EMP_102:100:100:五月:2013
WF_101:EMP_103:100:80:五月:2013
所以SalesRep可以有很多工作流程。 但我想为当前的月份和年份的每个SalesRep的第一个。
你是什么排序? – Rachcha 2013-05-13 19:36:11
Order By SalesRepId,WorkflowId和每个SalesRepId我想要SalesRepId的第一行。 – Vijay 2013-05-13 19:42:32