Sql Postgres查询以返回用户的所有结果
在标记学生的证据时,我展示的只是一份结果列表。评估员(负责标记学生证据)想知道结果是否已经部分或完全满足 我一直在处理一个SQL查询,该查询返回一个学生的结果,以及这些结果是部分满足还是完全满足Sql Postgres查询以返回用户的所有结果,sql,ruby-on-rails,postgresql,Sql,Ruby On Rails,Postgresql,在标记学生的证据时,我展示的只是一份结果列表。评估员(负责标记学生证据)想知道结果是否已经部分或完全满足 我一直在处理一个SQL查询,该查询返回一个学生的结果,以及这些结果是部分满足还是完全满足 学生们有很多证据 证据有很多证据 证据有很多结果,通过证据和结果 证据结果属于证据 证据结果属于结果 学生有许多单元,通过注册单元 单元有很多结果 对于每个结果,我必须: 获取结果内容,检查是否有属于学生证据的证据结果(部分满足该结果),最后检查是否有属于学生证据的证据结果(完全满足该结果) 我的模
- 学生们有很多证据
- 证据有很多证据
- 证据有很多结果,通过证据和结果
- 证据结果属于证据
- 证据结果属于结果
- 学生有许多单元,通过注册单元
- 单元有很多结果
# Table name: company_students
#
# id :bigint not null, primary key
has_many :evidences
has_many :units, through: :enrolled_units,
================
# Table name: company_student_enrolled_units
#
# id :bigint not null, primary key
# completed :boolean default(FALSE)
# student_id :integer
# unit_id :integer
belongs_to :student
belongs_to :unit
================
# Table name: curriculum_evidences
#
# id :bigint not null, primary key
# description :text
# title :string
# assigned_coursework_id :integer
# student_id :integer
has_many evidences_outcomes
has_many outcomes through evidence_outcomes
================
# Table name: curriculum_outcomes
#
# id :bigint not null, primary key
# code :text
# content :text
# position :integer
# outcome_group_id :integer
# unit_id :integer
has_many :evidence_outcomes
has_many :evidences through evidence_outcomes
================
# Table name: curriculum_evidence_outcomes
#
# id :bigint not null, primary key
# meets_outcome :boolean default(FALSE)
# partially_met :boolean default(FALSE)
# curriculum_id :integer
# enrolled_unit_id :integer
# evidence_id :integer
# outcome_id :integer
# student_id :integer
belongs_to :evidence
belongs_to :outcome
================
已尝试修改我的联接,但未成功
SELECT DISTINCT CASE WHEN partially_met='f'
THEN 'True'
ELSE 'False'
END AS Partially_met,
co.id AS outcome_id,
co.unit_id,
co.content,
students.id AS student_id
FROM company_students AS students
JOIN curriculum_evidences
AS ce
ON students.id = ce.student_id
LEFT JOIN curriculum_evidence_outcomes ceo
ON ce.id = ceo.evidence_id
LEFT JOIN curriculum_outcomes
AS co
ON co.id=ceo.outcome_id
LEFT JOIN curriculum_evidences
AS cev
ON cev.student_id=ceo.student_id
WHERE students.id = 901
ORDER BY co.content asc
我对SQL的了解有限,我的查询只是返回一个学生(本例中为学生901)与之相关的结果,但我想得到所有结果,您的问题很难理解。“我想得到所有的结果”是什么意思?您没有
结果
模型。你是说你想得到所有的课程成果吗?因为你有一个课程结果
模型。如果你真的想要所有这些,那么就去做课程结果.all
。但是,我怀疑这不是你想要的答案。或者是吗?如果查询适用于学生901,那么如果您想要所有学生的结果,只需删除WHERE students.id=901
?您的问题很难理解。“我想得到所有的结果”是什么意思?您没有结果
模型。你是说你想得到所有的课程成果吗?因为你有一个课程结果
模型。如果你真的想要所有这些,那么就去做课程结果.all
。但是,我怀疑这不是你想要的答案。或者是吗?如果查询适用于学生901,那么如果您想要所有学生的结果,只需删除WHERE students.id=901
?