1

私は次のようなクエリを開発しました

select accountname count(transactions)
from table1 group by accountname
where date between '27-mar-2012' and '27-jan-2013'

しかし、演算子間を考慮せずにすべてのトランザクションを提供しています。つまり、1月から12月までのすべての値を考慮しています。私のテーブルには、2012 年 3 月 27 日のような日付列の値が含まれています ...

私が使用する場合

select accountname count(transactions) from table1
group by accountname
where date between cast('27-mar-2012' as date) and cast( '27-jan-2013' as date)

私は間違った結果を得ています。

どうすれば修正できますか?

4

1 に答える 1

1

1 つの可能性は、Oracle がクエリを実行していることです。

select accountname, count(transactions)
from table1
group by accountname

where.の後に句が無効であるためですgroup by

私は提案します:

select accountname, count(transactions)
from table1
where date between to_date('2012-03-27', 'yyyy-mm-dd') and to_date('2013-01-27', 'yyyy-mm-dd')
group by accountname

to_date()よりも安全ですconvert()。また、ANSI 標準の日付形式を使用することをお勧めします (IMHO)。

于 2013-04-24T21:54:09.443 に答える