我正在尝试使用连接到 MySQL 数据库的 ASP.NET 创建一个 GridView。数据如下所示。
BusinessUnit OrderDate Canceled
UnitA 1/15/2013 N
UnitA 10/1/2013 N
UnitB 10/15/2013 N
UnitB 10/22/2013 N
UnitB 10/22/2013 N
根据上面的记录,我希望结果如下所示
BusinessUnit TodaysOrders ThisMonthsOrders ThisYearsOrders
UnitA 0 1 2
UnitB 2 3 3
我当前的代码如下。它给了我错误(关于 DatabaseName.sum 的东西不存在。检查函数名称解析和解析部分......)
Select
SUM (CASE WHEN (OrderDate)=DATE(NOW()) THEN 1 ELSE 0 END) AS TodaysOrders,
SUM (CASE WHEN YEAR(OrderDate) = YEAR(CURDATE()) AND MONTH(OrderDate) = MONTH(CURDATE()) THEN 1 ELSE 0 END) AS ThisMonthsOrders,
SUM (CASE WHEN YEAR(main_order_managers.creation_date) = YEAR(CURDATE()) THEN 1 ELSE 0 END) AS ThisYearsOrders
代码继续
FROM OrderTable WHERE OrderTable.Canceled. <> 'Y';
Sum Case 是这里的最佳用途吗?