SELECT
*
FROM
(
SELECT
id,
br_code,
NAME,
appointmenttype,
telephone,
bigcash,
remark,
apt_status,
operation_time,
valid_code
FROM
(
SELECT
a.id,
a.br_code,
a. NAME,
b. NAME AS appointmenttype,
a.telephone,
a.bigcash,
a.remark,
a.apt_status,
a.operation_time,
a.valid_code
FROM
(
jkh_para_aptmanage a
LEFT JOIN jkh_para_appointmenttype b ON ((a.apt_type = b. CODE))
)
WHERE
a.apt_status = 'Y01'
ORDER BY
a.apt_status,
a.apt_time
) A
UNION ALL
SELECT
id,
br_code,
NAME,
appointmenttype,
telephone,
bigcash,
remark,
apt_status,
operation_time,
valid_code
FROM
(
SELECT
a.id,
a.br_code,
a. NAME,
b. NAME AS appointmenttype,
a.telephone,
a.bigcash,
a.remark,
a.apt_status,
a.operation_time,
a.valid_code
FROM
(
jkh_para_aptmanage a
LEFT JOIN jkh_para_appointmenttype b ON ((a.apt_type = b. CODE))
)
WHERE
a.apt_status = 'Y02'
ORDER BY
a.apt_status,
a.operation_time DESC
) B
) C
LIMIT 0,
5;
*
FROM
(
SELECT
id,
br_code,
NAME,
appointmenttype,
telephone,
bigcash,
remark,
apt_status,
operation_time,
valid_code
FROM
(
SELECT
a.id,
a.br_code,
a. NAME,
b. NAME AS appointmenttype,
a.telephone,
a.bigcash,
a.remark,
a.apt_status,
a.operation_time,
a.valid_code
FROM
(
jkh_para_aptmanage a
LEFT JOIN jkh_para_appointmenttype b ON ((a.apt_type = b. CODE))
)
WHERE
a.apt_status = 'Y01'
ORDER BY
a.apt_status,
a.apt_time
) A
UNION ALL
SELECT
id,
br_code,
NAME,
appointmenttype,
telephone,
bigcash,
remark,
apt_status,
operation_time,
valid_code
FROM
(
SELECT
a.id,
a.br_code,
a. NAME,
b. NAME AS appointmenttype,
a.telephone,
a.bigcash,
a.remark,
a.apt_status,
a.operation_time,
a.valid_code
FROM
(
jkh_para_aptmanage a
LEFT JOIN jkh_para_appointmenttype b ON ((a.apt_type = b. CODE))
)
WHERE
a.apt_status = 'Y02'
ORDER BY
a.apt_status,
a.operation_time DESC
) B
) C
LIMIT 0,
5;
本文介绍了一种使用 SQL 进行复杂数据筛选的方法,通过联表查询和条件筛选实现对特定状态的预约信息进行分组和排序展示。具体包括如何通过 LEFT JOIN 实现表关联,以及如何设置 WHERE 子句来过滤数据。
673

被折叠的 条评论
为什么被折叠?



