sql - query last Renewal of licences -
suppose have client renewal of licences every year. how query last year clients had renew licences per section... tried code , worked fine produce max year in section i.e 2014 though there clients have no renew licences since 2012...
select @last_expired_date = max(expired_license_date) entrepreneur right outer join firm_info on entrepreneur.entre_id = firm_info.entre_id right join section on firm_info.section_id = section.section_id right join license on firm_info.firm_no = license.firm_no right join license_operations on license.license_serial = license_operations.license_serial section.section_id = @section_no group license.license_serial
you need add client name select
, group by
clause, give list of clients , latest year have renewed license.
as note: use alias table names in joins. helps identify columns come tables. additionally avoid using right join
because can make harder understand data getting.
Comments
Post a Comment