Sql 使用 WHERE 对 ORDER BY 进行排序

Tsql Sorting an ORDER BY with WHERE

我正在从事 .net 图表控件项目,并且是 sql 的新手。我希望能够对来自文本框输入的日期进行排序。

SELECT Employee.[First Name] + ' ' + Employee.[Last Name] AS 'Name',
sum(Time.[Total Hours]) AS 'Total Hours'
, FORMAT([Time].[Time in], 'd', 'en-gb') AS 'Worked On'
FROM Employee
inner join [Time] on
Employee.ID =  Time.EmployeeIdFK 
GROUP BY FORMAT([Time].[Time in], 'd', 'en-gb')
,Employee.[First Name] + ' ' + Employee.[Last Name]

--WHERE Time.[Time in] between '6/23/2016' and '7/26/2016'

到目前为止 运行 我得到的查询。这只是我正在测试的 dummy.mdf。

Name                                 Total Hours            Worked On
------------------------------------ ---------------------- -----------
Cola Coco                            11.3332033110278       23/07/2016
Cola Coco                            0.00417034752421024    26/07/2016
Lmimited Pepsi                       14.2175327702778       23/07/2016
Lmimited Pepsi                       2.9601598583878E-07    24/07/2016
Lmimited Pepsi                       1.05082415577342E-06   26/07/2016

我要补充

WHERE Time.[Time in] between '6/23/2016' and '7/26/2016'

或类似的东西,这样我就可以从文本框中输入日期。

--更新--

感谢您的评论,我一直将 WHERE 放在 GROUP BY 之后,这一直给我一个错误。

 SELECT Employee.[First Name] + ' ' + Employee.[Last Name] AS 'Name',
 sum(Time.[Total Hours]) AS 'Total Hours'
 , FORMAT(Time.[Time in], 'd', 'en-gb') AS 'Worked On'
 FROM Employee
 inner join Time on
 Employee.ID = Time.EmployeeIdFK 
 WHERE Time.[Time in] between '6/23/2016' and '7/26/2016'
 GROUP BY FORMAT(Time.[Time in], 'd', 'en-gb')
 ,Employee.[First Name] + ' ' + Employee.[Last Name]

Name                                 Total Hours            Worked On
------------------------------------ ---------------------- -----------
Cola Coco                            11.3332033110278       23/07/2016
Lmimited Pepsi                       14.2175327702778       23/07/2016
Lmimited Pepsi                       2.9601598583878E-07    24/07/2016

这现在工作正常。