我有一个患者表和treatment_patient,其中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);
插入treatment_patients;
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行)
答案 0 :(得分:3)
Cassandra只在分区内进行排序。由于结果集包含来自多个分区(treapat_uuid
)的行,因此您的数据不会在该级别进行排序。但是,它将在共享同一分区的行中进行排序,即treapat_uuid
中的行按升序排序。
treatpat_uuid | patid | diagnosis
--------------+-------+-----------
...
789 | 1 | Allergy
789 | 2 | flu
...