0

私は何かに苦しんでいて、自分でそれを理解する時間があまりありません。

私のクエリ:

   Select distinct d.delivery_bay_code,dt.diary_type_desc, d.delivery_datetime, ddo.order_no , ddo.company_id_no,  ddo.no_of_cartons, s.supplier_name, c.company_name, sk.sku_desc, (pod.deliver_not_after_date)||' '||(pod.deliver_not_before_date)as delivery_window
     from diary d , dc_diary_order ddo , purch_order po ,purch_order_carton_sku pocs ,sku sk, purch_order_date pod,supplier s , diary_type dt , company c
    where ddo.diary_entry_id_no = d.diary_entry_id_no
      and po.order_no = ddo.order_no
      and po.company_id_no = ddo.company_id_no
      and s.supplier_id_no = po.supplier_id_no
      and s.company_id_no = po.company_id_no
      and dt.diary_type_code = d.diary_type_code
      and c.company_id_no = po.company_id_no
      and po.order_no = pocs.order_no
      and pocs.sku_id_no = sk.sku_id_no
      and po.company_id_no = 2
      and ddo.order_no = 1999
      order by delivery_datetime;

このクエリは、 のみがdelivery_window異なる 2 つのレコードを返します。たとえば13/APR/11 13/APR/11 and 12/APR/11 12/APR/11、最大の日時(最新の日付)のみを戻すようにします。

例えば:select max(delivery_datetime) from diary;

今、私は上記のクエリを次のように試しました:

select... max(pod.deliver_not_after_date)||' '||(pod.deliver_not_before_date)as delivery_window ... from

しかし、私はエラーが発生しますORA-00937: not a single-group group function

4

1 に答える 1

1

GROUP BYonが欠落しているためpod.deliver_not_before_date、エラー メッセージが表示されます。

select... max(pod.deliver_not_after_date)||' '||(pod.deliver_not_before_date)as delivery_window ... from ..... GROUP BY pod.deliver_not_before_date

またはその他のグループ化関数を使用するMAX()場合、グループ化関数を持たない他のすべての列をGROUP BYSQL ステートメントの一部に配置する必要があります。

各注文の最新の日付の行のみを取得するには、次のようなものを使用できます。

   select *
       from (
             Select distinct d.delivery_bay_code,dt.diary_type_desc, d.delivery_datetime, ddo.order_no , ddo.company_id_no,  ddo.no_of_cartons, s.supplier_name, c.company_name, sk.sku_desc, (pod.deliver_not_after_date)||' '||(pod.deliver_not_before_date)as delivery_window
             , max(pod.deliver_not_after_date) over (partition by ddo.order_no order by ddo.order_no) max_deliver_not_after_date
          from diary d , dc_diary_order ddo , purch_order po ,purch_order_carton_sku pocs ,sku sk, purch_order_date pod,supplier s , diary_type dt , company c
            where ddo.diary_entry_id_no = d.diary_entry_id_no
          and po.order_no = ddo.order_no
          and po.company_id_no = ddo.company_id_no
          and s.supplier_id_no = po.supplier_id_no
          and s.company_id_no = po.company_id_no
          and dt.diary_type_code = d.diary_type_code
          and c.company_id_no = po.company_id_no
          and po.order_no = pocs.order_no
          and pocs.sku_id_no = sk.sku_id_no
          and po.company_id_no = 2
          and ddo.order_no = 1999
          order by delivery_datetime)
      where deliver_not_after_date = max_deliver_not_after_date;
于 2013-03-19T08:28:32.407 に答える