-2

SQLに問題があります。ステートメントの合計最大数を1行にしようとしましたが、機能しません。警告メッセージは、「)」の近くの構文が正しくないことを示しています。これは私のコードです:-

select sum(A) from (select t.ticketid, lt.description ticketsource,
c.description tickedcreted,
max_score = isnull(
(select max(si.marks) as max_score
from survey_items si
left join survey_questions sq on (si.question_id = sq.question_id)
left join survey s on (sq.survey_id = s.survey_id
and s.code_interaction= 1)),0
),
sum(si.marks) totalAnswer,

count(t.ticketid) totalticketcreated,
count(t.feedback) totalfeedbackreceived
from  survey_items si
left join lookup_questions lq on (si.item_id = lq.item_id)
left join feedback fb on (fb.feedback_id = lq.feedback_id)
left join ticket t on (t.ticketid = fb.ticketid)
left join survey_questions sq on (si.question_id = sq.question_id)
left join survey s on (sq.survey_id = s.survey_id)
left join lookup_assignedOfficer c on (c.code = t.enteredby )
left join lookup_department ld on t.department_code =ld.code
left join lookup_ticketsource lt on lt.code = s.code_interaction
where t.trashed_date is null and lt.enabled =1 and ld.description is not null
and
((t.assigned_date BETWEEN '7/16/2012' AND '7/16/2012'))
)
4

1 に答える 1

2

selectステートメントから取得した結果セットをテーブルとして使用する場合は、エイリアス名をテーブルに渡す必要があります。

これを試して:

select sum(A) from 
(
    select t.ticketid, lt.description ticketsource,
    c.description tickedcreted,
    max_score = isnull(
    (select max(si.marks) as max_score
    from survey_items si
    left join survey_questions sq on (si.question_id = sq.question_id)
    left join survey s on (sq.survey_id = s.survey_id
    and s.code_interaction= 1)),0
    ),
    sum(si.marks) totalAnswer,

    count(t.ticketid) totalticketcreated,
    count(t.feedback) totalfeedbackreceived
    from  survey_items si
    left join lookup_questions lq on (si.item_id = lq.item_id)
    left join feedback fb on (fb.feedback_id = lq.feedback_id)
    left join ticket t on (t.ticketid = fb.ticketid)
    left join survey_questions sq on (si.question_id = sq.question_id)
    left join survey s on (sq.survey_id = s.survey_id)
    left join lookup_assignedOfficer c on (c.code = t.enteredby )
    left join lookup_department ld on t.department_code =ld.code
    left join lookup_ticketsource lt on lt.code = s.code_interaction
    where t.trashed_date is null and lt.enabled =1 and ld.description is not null
    and
    ((t.assigned_date BETWEEN '7/16/2012' AND '7/16/2012'))
) AS result

次に、列Aの合計を見つけようとしましたが、列Aが結果セットに存在しません。

于 2012-07-29T10:26:03.467 に答える