親と子のデータベースがあり、子は親に起こったことの一種の実行中のトランスクリプトを保持しているとしましょう:
create table patient (
fullname text not null,
admission_number integer primary key
);
create table history (
note text not null,
doctor text not null,
admission_number integer references patient (admission_number)
);
(ほんの一例です。私は医療アプリケーションを行っていません)。
history
同じに対して多くのレコードがありますadmission_number
:
admission_number doctor note
------------------------------------
3456 Johnson Took blood pressure
7828 Johnson EKG 120, temp 99.2
3456 Nichols Drew blood
9001 Damien Discharged patient
7828 Damien Discharged patient with Rx
それで、私の質問は、patient
たとえば、病歴に「血圧」と「除隊」。
現在、私はそのグループに対して を実行select
しており、すべてのメモを で結合し、 で検索を行っています。history
admission_number
group_concat(note)
having
select * from history
group by admission_number
having group_concat(note) like '%blood pressure%'
and group_concat(note) like '%discharged';
これは機能しますが、特定の精緻化が非常に複雑になります。たとえば、「病歴に「血圧」が含まれていて、ダミアン博士との病歴に「退院」と書かれているすべての患者に質問できるようにしたいと考えています。私の基本的なクエリの上にこのような資格を追加するのは非常に面倒です。
私の基本的なクエリを表現するより良い方法はありますか?