我正在尝试编写MySQL查询以获得每月平均值,从给定日期之间的所有月份.我的想法是这样的:
查询,类似于
SELECT AVG(value1) as avg_value_1,
AVG(value2) as avg_value_2,
MONTH(save_date) as month,
YEAR(save_date) as year
FROM myTable
WHERE save_date BETWEEN '2009-01-01' AND '2009-07-01'
GROUP BY YEAR(save_date), MONTH(save_date)
avg_value_1 | avg_value_2 | month | year
5 | 4 | 1 | 2009
2 | 1 | 2 | 2009
7 | 5 | 3 | 2009
0 | 0 | 4 | 2009 <---
6 | 5 | 5 | 2009
3 | 6 | 6 | 2009
Run Code Online (Sandbox Code Playgroud)
你看,在2009年4月期间没有输入任何值,但我希望它在输出中显示为0,0值.关于如何实现这一点的任何想法?可以在MySQL内完成吗?
我正在做一个带有书架的小型ASP.NET MVC 3测试应用程序,我可以在其中列出"书籍",并向"Loaners"贷款并将其返回.
我想在一个视图上显示我的书籍和我的Loaners,并因此创建了一个名为BooksViewModel的ViewModel,但我无法弄清楚为什么我无法列出我的"书籍".我可以做"foreach(模型中的var项目)",只触摸里面的"Books",没有Books属性.
我的模特
namespace MyTest.Models
{
/// <summary>
/// Represents a book
/// </summary>
public class Book
{
public int ID { get; set; }
public string Title { get; set; }
public string Author { get; set; }
public string ISBN { get; set; }
public virtual Loaner LoanedTo { get; set; }
}
/// <summary>
/// Represents a Loaner
/// </summary>
public class Loaner
{
public int ID { get; set; }
public string Name { …Run Code Online (Sandbox Code Playgroud) 我的"Bookshelf"测试应用程序中有两个POCO:
/// <summary>
/// Represents a book
/// </summary>
public class Book
{
public int ID { get; set; }
public string Title { get; set; }
public string Author { get; set; }
public string ISBN { get; set; }
public virtual Loaner LoanedTo { get; set; }
}
/// <summary>
/// Represents a Loaner
/// </summary>
public class Loaner
{
public int ID { get; set; }
public string Name { get; set; }
public virtual ICollection<Book> Loans …Run Code Online (Sandbox Code Playgroud)