-1

我有一个患者表和治疗患者,其中 pat_id 充当外键。我想执行一个查询,使treatment_patient 始终返回按pat_id 排序的值。我尝试添加 WITH CLUSTERING ORDER BY (patid ASC); 最后但没有工作。

CREATE TABLE patient(
record_id uuid PRIMARY KEY,
patid int,
name text,
dob timestamp
);

插入患者:

insert into patient (record_id, patid, name, dob) values (uuid(), 123, 'John Doe', '2015-01-01 22:00');
insert into patient (record_id, patid, name, dob) values (uuid(), 456, 'Joy Smith', '2014-11-01 21:00');

Treatment_Patients 表:

CREATE TABLE treatments_patients(
treatpat_uuid int,
patid int,
diagnosis text,
PRIMARY KEY(treatpat_uuid,patid)
) WITH CLUSTERING ORDER BY (patid ASC);

插入治疗_患者;

insert into treatments_patients (treatpat_uuid, patid, diagnosis) values (123, 011, 'Cold');
insert into treatments_patients (treatpat_uuid, patid, diagnosis) values (456, 006, 'Cough');
insert into treatments_patients (treatpat_uuid, patid, diagnosis) values (789, 002, 'flu');
insert into treatments_patients (treatpat_uuid, patid, diagnosis) values (12, 231, 'Acne');
insert into treatments_patients (treatpat_uuid, patid, diagnosis) values (789, 001, 'Allergy');

输出:

treatpat_uuid | patid | diagnosis
---------------+-------+-----------
123 |    11 |      Cold
456 |     6 |     Cough
789 |     1 |   Allergy
789 |     2 |       flu
12 |   231 |      Acne

(5 行)

4

1 回答 1

3

Cassandra 仅在分区内进行排序。由于您的结果集包含来自多个分区 ( treapat_uuid) 的行,因此您的数据不会在该级别排序。但是,它将在共享同一分区的行中排序,即您的行中的行treapat_uuid按升序排序。

treatpat_uuid | patid | diagnosis
--------------+-------+-----------
...
          789 |     1 |   Allergy
          789 |     2 |       flu
...
于 2015-12-12T23:43:34.500 回答