Hello Stack Overflow社区 - 希望我能在这个问题上走上正轨,但我正在尝试编写一个查询,其中一份报告显示按月/年排列的订单数量。该报告目前提出我试图按月/年集体加入所有这些日子。希望这是有道理的,我对此很新,请温柔一点;)
select distinct month(o.orderdate) 'Month',
year(o.orderdate) 'Year', sum(od.Quantity) as Orders
from OrderDetails od
join Products p
on od.ProductID = p.ProductID
join Orders o
on od.OrderID = o.OrderID
group by o.orderdate
Order by year, month asc;
答案 0 :(得分:2)
您需要group by
想要定义每一行的内容。在您的情况下,即年和月:
select year(orderdate) as yyyy, month(o.orderdate) as mm,
sum(od.Quantity) as Orders
from OrderDetails od join
Products p
on od.ProductID = p.ProductID join
Orders o
on od.OrderID = o.OrderID
group by year(o.orderdate), month(o.orderdate)
Order by yyyy, mm asc;
注意:
yyyy
和mm
,因此不会与保留字year
和month
冲突。as
作为列别名(以帮助防止丢失逗号错误),但从不使用表别名。product
表。编辑:如果您想查询订单,请查询建议,那么这可能更合适:
select year(o.orderdate) as yyyy, month(o.o.orderdate) as mm,
count(*) as Orders
from orders o
group by year(o.orderdate), month(o.orderdate)
Order by yyyy, mm asc;
答案 1 :(得分:0)
您必须按月和年分组
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<!-- Replace example.com with www.example.com if that is what you registered on your hosting service-->
<key>example.com</key>
<!-- instead of http://example.com -->
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
</dict>
</dict>