我有一个专家表,其中包含expert_description
,company_description
,expert_website
,expert_email
,company_website
等字段。
这些字段不是必需的,因此它们可能是NULL
。
搜索表格时,首先应包含大多数非NULL
字段的条目。
例如,有四个用户:
结果应为
答案 0 :(得分:0)
我建议你在用户表中创建一个字段,用于存储填充字段的数量。
每次用户添加/删除字段时都应更新此列。
然后你只需按" fieldcount"列。
答案 1 :(得分:0)
如果空字段的值为NULL,则可以使用此类内容。
SELECT expert_description, company_description, expert_website, expert_email, company_website,
((expert_description IS NULL) + (company_description IS NULL) + (expert_website IS NULL) + (expert_email IS NULL) + (company_website IS NULL)) AS empty_count
FROM experts
WHERE 1
ORDER BY empty_count;
如果字段的值为1
, IS NULL将返回NULL
,否则它将返回0
。
答案 2 :(得分:0)
使用此查询:
SELECT user FROM your_table
ORDER BY expert_description DESC, company_description DESC,
expert_website DESC, expert_email DESC, company_website DESC;
谢谢。
答案 3 :(得分:0)
这对我有用
select * from table
order by if(field = '' or field is null,1,0),field
从@Rossco建议的链接中得到了这个答案