0

このクエリをパーベイシブ データベースで実行しようとしています

select cust_no,cust_name,sum(bvtotal) as Amount
from sales_history_header  
where cust_no is not null and number is not null and bvtotal > 1000 and in_date < 20140101
group by cust_no,cust_name
order by sum(bvtotal) desc;

サブ結果に in_date > 20140101 が含まれるグループ結果を除外するにはどうすればよいですか?

私が持っているこのクエリは、in_date > 20140101 の結果も取得しています。

私は何か間違っていますか?

私が得ているサンプル出力はこの形式です

cust_no     cust_name      amount
A             a1            500
B             b1            500
C             c1            1000

cust_no 'A' のこのレコードを除外したいのは、20140202 の in_date で取引があったためです

生データで次のようなレコードがあることを考慮してください

cust_no     cust_name      amount    in_date
A             a1            100      20130203
A             a1            400      20130101
A             a1            1000     20140503
4

3 に答える 3

0

何が必要なのか正確にはわかりませんが、

しかし、INT型とDATE型を混在させているようです。

したがって、in_dateフィールドのタイプがDATEの場合

select 
  cust_no,
  cust_name,
  sum(bvtotal) as Amount
from sales_history_header  
where cust_no is not null 
  and number is not null 
  and bvtotal > 1000 
  and in_date < DATE('2014-01-01')
group by cust_no,cust_name
order by sum(bvtotal) desc;

in_dateフィールドのタイプがTIMESTAMPの場合

select 
  cust_no,
  cust_name,
  sum(bvtotal) as Amount
from sales_history_header  
where cust_no is not null 
  and number is not null 
  and bvtotal > 1000 
  and in_date < TIMESTAMP('2014-01-01 00:00:00')
group by cust_no,cust_name
order by sum(bvtotal) desc;
于 2015-03-11T19:09:57.790 に答える