2013-03-25 107 views
0

我有一個表作爲支付ASP.Net Web應用程序轉移到另一臺計算機

ser. paymentdate amount 
1. 12 mar 2007 5000 
1. 14 mar 2007 5000 
2. 6 dec 2007 4000 
3. 2 mar 2008 6000 
4. 5 nov 2008 2000 

我想一個月 從表中選擇組數據,例如2007年

month amount 
mar  10000 
dec  4000 

我能得到的數據記錄明智的通過這個查詢,但不是明智的。

+0

什麼是您的付款日期的類型,是字符串還是日期時間? – wizzardz 2013-03-25 05:23:17

回答

0

請嘗試:

SELECT 
    DATENAME(m, paymentdate) [Month], 
    SUM(Amount) AS Amount 
FROM 
    Payment 
WHERE 
    YEAR(paymentdate)=2007 
GROUP BY DATENAME(m, paymentdate), MONTH(paymentdate) 
ORDER BY MONTH(paymentdate) 
+0

感謝您的回覆:D – 2013-03-25 06:32:30

0

的SQL LIKE子句用來比較的值使用通配符運營商類似的值。有兩個通配符與LIKE運算符一起使用:

The percent sign (%) 
The underscore (_) 

百分號表示零個,一個或多個字符。下劃線表示單個數字或字符。這些符號可以組合使用。

WHERE SALARY LIKE '%200%' 

發現,在任何位置

所以要根據您的病情,需要一定的變量,它包含要進行選擇,然後把語句像這個月有200的任何值,

WHERE SALARYDATE LIKE '%mar%' 

或 一些其他的選擇

WHERE SALARY LIKE '200%' Finds any values that start with 200 
WHERE SALARY LIKE '%200%' Finds any values that have 200 in any position 
WHERE SALARY LIKE '_00%' Finds any values that have 00 in the second and third positions 
WHERE SALARY LIKE '2_%_%' Finds any values that start with 2 and are at least 3 characters in length 
WHERE SALARY LIKE '%2' Finds any values that end with 2 
WHERE SALARY LIKE '_2%3' Finds any values that have a 2 in the second position and end with a 3 
WHERE SALARY LIKE '2___3' Finds any values in a five-digit number that start with 2 and end with 3 
相關問題