MySQL calculated column using two tables -
i've got table of clubmembers integer id (pk)
i've got table lists couple of ids (life members of club)
i want create view clubmembers, plus column calculates membership type works this:
if (clubmember.id in lifemembers) result = "life" elseif (clubmember.datejoinedclub on 1 year ago) result = "full" else result = "probationary"
but have no idea how in sql.
use left join
, case
, this:
select cm.*, case when lm.id not null 'life' when now() > date_add(cm.datejoinedclub, interval 1 year) 'full' else 'probationary' end `result` clubmembers cm left join lifemembers lm on cm.id = lm.id
Comments
Post a Comment