c# - 我想从 MySQL 数据库中检索去年的记录,但它正在从数据库中检索所有数据

标签 c# mysql asp.net

string cmd = @"
SELECT Status,COUNT(Status),YEAR(Start_Date_Time) As LASTYEAR 
FROM sh_report 
WHERE 'YEAR(Start_Date_Time)' <= DATE_SUB(CURDATE(),INTERVAL 1 YEAR) 
GROUP BY YEAR(Start_Date_Time)";

问题是获取所有记录,但我只想从数据库中获取最近一年的记录,任何人都可以告诉我 MYSQL 查询以获取最近一年的记录。

最佳答案

您需要使用LIMIT 来获得您想要的。 Here is more info on the LIMIT .

     SELECT Status,COUNT(Status),YEAR(Start_Date_Time) As LASTYEAR 
     FROM sh_report 
     WHERE YEAR(Start_Date_Time) <= DATE_SUB(CURDATE(),INTERVAL 1 YEAR) 
     GROUP BY YEAR(Start_Date_Time)
     ORDER BY YEAR(Start_Date_Time) Asc
     LIMIT 1

关于c# - 我想从 MySQL 数据库中检索去年的记录,但它正在从数据库中检索所有数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28599680/

相关文章:

c# - 适用于 ASP.NET MVC/C# 的 WFS(网络特征服务)

c# - 在 Xamarin Forms 中浏览层次结构的设计模式是什么?

php - 相对MySQL数据库

c# - 在另一个CheckBox的基础上勾选取消勾选所有CheckBox

c# - 如何避免使用 selenium 在 chrome 自动化中弹出 'This type of file can harm your computer'

c# - 如何在 XNA 中为绘制的线条添加 Z 深度透视图?

c# - 无法使SQL Server Compact 3.5/4与ASP .NET MVC 2一起使用

javascript - prompt() 与 Internet Explorer 8

php - 使用数组在选择元素中输出的mysql查询

java.sql.SQLException :No suitable driver found for jdbc:mysql://localhost/myDB 异常