0

私は3つのテーブルを持っています

table A
------------------------------------------
filing_no | pet_name | res_name | court_no
------------------------------------------
1         | xyz      | PQR      |  1
------------------------------------------
2         | abc      | def      |  2
------------------------------------------


Table B
-------------------------------
filing_no |purpose_code|next_date
-----------------------------------
2         | 20         |3/8/2012
-----------------------------------
1         | 21         |3/9/2012
-----------------------------------
2         | 22         |3/10/2012
-----------------------------------
1         | 23         |15/11/2012
-----------------------------------

Table C.
-------------------------------------
purpose_code | purpose_name
-------------------------------------
20           | institution
-------------------------------------
21           | summon
-------------------------------------
22           | proceeding
-------------------------------------
23           | order
-------------------------------------

そして私は次のような特定の裁判所の結果が欲しいです:

--------------------------------------------------------
filing_no| Pet_name | res_name |purpose_name| next_date
--------------------------------------------------------
1        | xyz      | PQR      | Order      | 15/11/2012

以下のクエリを実行すると、#1111-グループ関数ERRORの使用が無効になります。助けてください。

select 

    a.filing_no as "File No", a.case_no as "Registration No", a.pet_name as Petitioner, a.res_name as Accused,  
    a.dt_of_filing as "Date of Inst",MAX(b.Next_date) as "Next Date",c.purpose_name as "Case Stage" 

from filing_t a, Daily_proc b, Purpose_t c 
where 
    a.filing_no = b.filing_no 
and c.purpose_code = (
          select purpose_code 
          from Daily_proc 
          where 
              filing_no = a.filing_no 
          and next_date = (
               select MAX(next_date) 
               from Daily_proc 
               where filing_no = a.filing_no
          )
    ) 
and a.court_no = 1 
and a.ci_cri = 2 
and a.status = 'P' 
group by b.filing_no 
order by a.dt_of_filing DESC LIMIT 0 , 2000
4

2 に答える 2

0

GROUP BY集計関数の列と結果のみを選択できます。たとえばa.pet_name、同じものに異なるものがある場合、何が返されると思いますb.filling_noか?

于 2012-11-08T11:14:48.960 に答える
0

@Devartが共有する回答私は彼にとても感謝しています。

SELECT a.filing_no、a.pet_name、a.res_name、c.purpose_name、b.next_date FROM a JOIN(SELECT * FROM(SELECT * FROM b ORDER BY filing_no、next_date DESC)t GROUP BY filing_no)b ON a.filing_no = b.filing_no JOIN c ON b.purpose_code = c.purpose_code WHERE a.court_no = 1;

于 2012-11-27T05:59:19.650 に答える