我有三张桌子
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 - 组函数的使用无效错误。请帮忙。
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