你知道如何从sql获得..只有一种..语言..
我的结果将返回
"user_languages" => "{"English":"Average","Bahasa Malaysia":"Good","Mandarin":"Don't Know","Tamil":"Don't Know"}"
例如:
select user_languages['English'] as custom_english
from MyTable
where user_languages = "English"
如果使用foreach肯定得到。但我需要一个SQL调用。
我正在使用创建报告..这是我的完整代码
英语/马来西亚语/普通话/泰米尔语如果不为空则有2.5 总共10,如果全部填写
$users = User::with(array())
->whereHas('roles', function ($q) {
$q->where('name', 'user');
})
->leftJoin(DB::raw('(
SELECT users.id, skill.user_languages,
(CASE WHEN pic IS NOT NULL THEN 10 ELSE 0 END) AS c_pic,
(CASE WHEN about_me IS NOT NULL THEN 10 ELSE 0 END) AS c_about_me,
(CASE WHEN full_name IS NOT NULL AND ic_passport IS NOT NULL AND dob IS NOT NULL AND gender IS NOT NULL AND race IS NOT NULL AND nationality IS NOT NULL AND prefer.expected_salary IS NOT NULL THEN 10 ELSE 0 END) AS c_my_details,
(CASE WHEN mobile_number IS NOT NULL AND email IS NOT NULL AND address_1 IS NOT NULL AND city IS NOT NULL AND postcode IS NOT NULL AND state IS NOT NULL AND country IS NOT NULL THEN 10 ELSE 0 END) AS c_my_contact,
(CASE WHEN skill.skill_description IS NOT NULL THEN 10 ELSE 0 END) AS c_skill_desc,
(CASE WHEN edu.school_name IS NOT NULL THEN 10 ELSE 0 END) AS c_education,
(CASE WHEN work.company_name IS NOT NULL THEN 10 ELSE 0 END) AS c_work,
(CASE WHEN skill.user_languages IS NOT NULL THEN 10 ELSE 0 END) AS c_language
FROM users
left join (SELECT * FROM user_preferences) prefer on users.id = (prefer.id)
left join (SELECT * FROM user_skill_language) skill on users.id = (skill.user_id)
left join (SELECT * FROM user_education GROUP BY user_id) edu on users.id = (edu.user_id)
left join (SELECT * FROM user_working_experience GROUP BY user_id) work on users.id = (work.user_id)
) user'), function($join)
{
$join->on(DB::raw("users.id"), '=', DB::raw("(user.id)"));
})
->selectRaw('users.id, users.email, users.mobile_number, users.full_name, users.race')
->selectRaw('(user.c_pic + c_about_me + c_my_details + c_my_contact + c_skill_desc + c_language + c_education + c_work ) as total_profile')
->orderBy($list_field, $list_sort)
->paginate(50);
答案 0 :(得分:0)
$langs = DB::table('your_table')
->where('user_languages->English', '!=', 'null')
->get();