0

私は支払いとして1つのテーブルを持っています

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

このクエリでは日付ごとにデータを取得できますが、月ごとには取得できません。

4

2 に答える 2

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)
于 2013-03-25T05:19:53.813 に答える
0

SQL LIKE句は、ワイルドカード演算子を使用して値を類似の値と比較するために使用されます。LIKE演算子と組み合わせて使用​​される2つのワイルドカードがあります。

The percent sign (%)
The underscore (_)

パーセント記号は、0文字、1文字、または複数文字を表します。アンダースコアは、単一の数字または文字を表します。記号は組み合わせて使用​​できます。

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
于 2013-03-25T05:21:25.493 に答える