龙空技术网

mysql三元表达式及排序

思源2020CZE6 224

前言:

此时朋友们对“mysql三元”大致比较注意,大家都想要了解一些“mysql三元”的相关文章。那么小编在网上汇集了一些有关“mysql三元””的相关资讯,希望看官们能喜欢,各位老铁们快快来学习一下吧!

需求介绍

有一场线上展会,有很多参展商参加,要求直播进行中的排序在前,其他按照sort排序。

字段概要

create table online_consultation_meeting_exhibitor(    id                             bigint unsigned auto_increment        primary key,  exhibitor_id                   int unsigned  not null comment '展商编号',    sort                           int default 1 not null comment '排序',    live_time_start                time          null comment '直播开始时间',    live_time_end                  time          null comment '直播结束时间',    exhibition_date                date          null comment '展会日期')    comment '线上展商' collate = utf8mb4_unicode_ci;
难点

如果判断进行中的线上展商,可以通过case when,或者三元表达式判断

代码

select  id,  live_time_start,  live_time_end,  exhibition_date,  IF(    concat(exhibition_date, ' ', live_time_start) <= current_timestamp    and current_timestamp <= concat(exhibition_date, ' ', live_time_end),    1,    2  ) as time_sortfrom  `online_consultation_meeting_exhibitor`order by  `time_sort` ,  `sort` desc

标签: #mysql三元