我试图弄清楚为什么它没有在结果中按顺序显示 form_id 以及如何让它按顺序显示。出于某种原因,它显示了这样的结果数据:
form_id question_id fq_concept_id fql_concept_id log_date fql_update_date fq_update_date 50008 6 null null null null 2020-08-21 50380 11 50385 null null null 2019-12-02 50399 8 50138 null null null 2020-03-05 50423 17 100 null null null 2020-07-02 50259 8 50084 null null null 2020-07-02 50265 1 50110 null null null 2020-08-30
use cust_dev
DECLARE @changedConcepts TABLE (form_id INT, question_id int, fq_concept_id INT, fql_concept_id int, log_date datetime, fql_update_date datetime, fq_update_date DATETIME )
--find changed concepts
insert into @changedConcepts
select FORM_QUESTION.FORM_ID,
FORM_QUESTION.QUESTION_ID,
FORM_QUESTION.CONCEPT_ID as fq_concept_id,
FQL.concept_id as fql_concept_id,
FQL.log_date,
FQL.update_date as fql_update_date,
FORM_QUESTION.update_date as fq_update_date
from [ck_dev].dbo.form_question
--ORDER BY fql.form_id asc, form_question.form_id asc, question_id asc
left JOIN
(SELECT DISTINCT
FORM_QUESTION_LOG.FORM_ID,
FORM_QUESTION_LOG.QUESTION_ID,
FORM_QUESTION_LOG.CONCEPT_ID,
FORM_QUESTION_LOG.log_date,
FORM_QUESTION_LOG.update_date --I think we need this date
FROM [ck_dev].dbo.FORM_QUESTION_LOG-- fql
) FQL
ON FQL.FORM_ID = FORM_QUESTION.FORM_ID
AND FQL.QUESTION_ID = FORM_QUESTION.QUESTION_ID
AND FQL.Concept_id <> FORM_QUESTION.concept_id
--group by
ORDER BY fql.form_id asc, form_question.form_id asc, fql.question_id asc, form_question.question_id asc
我有一种感觉,因为我的 form_id 来自不同的表,但我没有在搜索中找到(或如何修复它)。有没有办法让他们按顺序显示两个表格内容:
form_id question_id fq_concept_id fql_concept_id log_date fql_update_date fq_update_date 50008 6 null null null null 2020-08-21 50259 8 50084 null null null 2020-07-02 50265 1 50110 null null null 2020-08-30 50380 11 50385 null null null 2019-12-02 50399 8 50138 null null null 2020-03-05 50423 17 100 null null null 2020-07-02
答案 0 :(得分:0)
代替
ORDER BY fql.form_id asc, form_question.form_id asc, fql.question_id asc, form_question.question_id asc
我认为您应该使用以下顺序:
ORDER BY FORM_QUESTION.FORM_ID asc, fql.form_id asc, fql.question_id asc, form_question.question_id asc
或者你可以考虑删除 fql.form_id
ORDER BY FORM_QUESTION.FORM_ID asc, fql.question_id asc, form_question.question_id asc
fql.form_id 来自左连接中使用的表。因此,此列中可能有空值,但表 FORM_QUESTION 将始终具有值(除非 FORM_QUESTION.FORM_ID 是可空列)。