case when then end as

SELECT vtiger_crmentity.crmid, vtiger_crmentity.modifiedtime,vtiger_crmentity.smownerid,

case when (vtiger_users.user_name not like '')

then vtiger_users.user_name

else vtiger_groups.groupname

end as user_name,               

vtiger_cares.* FROM vtiger_cares

INNER JOIN vtiger_crmentity

ON vtiger_crmentity.crmid = vtiger_cares.caresid

INNER JOIN vtiger_carescf

ON vtiger_cares.caresid = vtiger_carescf.caresid

LEFT JOIN vtiger_caresgrouprelation

ON vtiger_cares.caresid = vtiger_caresgrouprelation.caresid

LEFT JOIN vtiger_groups

ON vtiger_groups.groupname = vtiger_caresgrouprelation.groupname

LEFT JOIN vtiger_users

ON vtiger_users.id = vtiger_crmentity.smownerid

WHERE vtiger_crmentity.deleted = 0

你可能感兴趣的:(case when)