2009-11-06 64 views
0

我有日期類型列(MySQL的):獲取不同的年份和月份亞音速

SELECT invdate FROM invoices; 

invdate 
------- 
2009-08-22 
2009-07-12 
2009-08-23 
------- 

,我希望得到的月和年這樣的:

SELECT DISTINCT MONTH(invdate) AS invmonth, YEAR(invdate) AS invyear FROM invoices; 

如何在C#中使用亞音速(SimpleRepository)?

TIA

回答

0

OMG!我忘了將變量定義爲日期/日期時間,所以我不能使用這些函數。

前:

public string invdate { get; set; } 

後:

public DateTime invdate { get; set; } 

我的錯,我很抱歉。 問題解決

1

您是否有機會查看文檔?請參閱下面的鏈接和代碼,它應該有所幫助。

http://subsonicproject.com/docs/Distinct

[Test] 
public void SqlQuery_when_setting_distinct_it_should_set_IsDistinct() 
{ 
    SubSonic.SqlQuery query= new 
     Select(Product.SupplierIDColumn).From<Product>().Distinct(); 
    Assert.IsTrue(query.IsDistinct); 
} 

[Test] 
public void SqlQuery_should_handle_distinct() 
{ 
    ProductCollection select = new 
     Select(Product.SupplierIDColumn).From<Product>().Distinct() 
     .ExecuteAsCollection<ProductCollection>(); 

    Assert.AreEqual(29, select.Count); 

} 

[Test] 
public void SqlQuery_GetRecordCount_should_handle_distinct() 
{ 
    int select = new Select(Product.SupplierIDColumn) 
     .From<Product>().Distinct() 
     .GetRecordCount(); 

    Assert.AreEqual(29, select); 
}