In a system there are registered plots . users can as plots with FamilyParcela where each user has their own / strong>.
plots are common to all.
I have 4 tables:
User that has classificar
PK Parcel that has cod_usuario
PK
Parcel Family that has cod_parcela
FK and cod_usuario
PK
Parcel_FamiliaParcela that has cod_familia
FK , cod_familia
fault , and a PK composed by cod_parcela
and cod_familia
Example usage:
We have 5 parcels registered
Horas extras além da 6a,
Horas extras além da 8a,
danos morais,
danos materiais,
periculosidade.
User 1 registers the families cod_parcela
, HORAS EXTRAS
and DANOS
that will belong only to him and can then sort
Horas extras além da 6a --> HORAS EXTRAS
Horas extras além da 8a --> HORAS EXTRAS
danos morais ---> DANOS
danos materiais ---> DANOS
periculosidade ----> OUTROS
And user 2 registers the OUTROS
and SALARIAL
families that will belong only to him and can then sort
Horas extras além da 6a --> SALARIAL
Horas extras além da 8a --> SALARIAL
danos morais ---> INDENIZATÓRIA
danos materiais ---> INDENIZATÓRIA
periculosidade ----> NULL ( DEIXAR SEM CLASSIFICAR )
When a user is using precision all plots with their PlotType and if it has not been sorted, return only the plot < strong> but only this user !
If I do
select *
from Parcela p
left outer join Parcela_FamiliaDeParcelas pf ON pf.cod_parcela = p.cod_parcela
left outer join FamiliaDeParcelas f on f.cod_familia = pf.cod_familia and f.cod_usuario = @codusuario
With this query for each ranking that the user does it returns 1 extra occurrence for each ranking of the same portion that another user did (but with INDENIZATÓRIA
in the data family )
If you add at the end a listar
it returns only the plots of the user , but not the unclassified plots
What should I do?