单列上的多个条件将数据返回到多列

时间:2021-05-01 15:37:05

标签: sql

我有一个查询,检索了大约 60 多个列,其中列名“资格”(sslc、hsc、文凭)及其各自的标记(“Sslc 标记”、“Hsc 标记百分比”、“文凭”)已在每个候选人都有不同的行。

例如。候选 'X' 具有 'hsc' 资格,那么候选 'x' 将在两行中检索,其中 sslc 标记为一列,而 hsc 标记另一列中的百分比

但需要检索数据为,每个候选人在同一行中针对各自的资格分数

Screenshot of csv file where data retrieved from query

The Model output for reference`

参考的现有查询 -

select 
pd.registration_no as "REGISTRATION NUMBER",
(case when edu.education_level_category_id='1' then 'sslc'
      when edu.education_level_category_id='2' then 'hsc' 
      when edu.education_level_category_id='3' then 'diploma' end )"QUALIFICATION",
(CASE WHEN qm.education_level_id='1' THEN qm.aggregate_percentage          
            END ) "SSLC MARKS",
(CASE WHEN qm.education_level_id='2' THEN qm.aggregate_percentage             
            END ) "HSC MARKS PERCENTAGE",
pd.applicant_cred_id as "APP CRED ID",
(CASE WHEN qm.education_level_id='1' THEN qm.certificate_number            
            END ) "SSLC SNO",
(CASE WHEN qm.education_level_id='3' THEN qm.aggregate_percentage             
            END ) "DIPLOMA",
            



from 
personal_details pd,
additional_details ad,
rps_exam_result res,
applicant_hallticket ah,
phase2_admit_card admit,
caste_category_master caste,
education_level_category edu,
qualification_master qm



where ad.applicant_cred_id=pd.applicant_cred_id
and
ah.applicant_cred_id=pd.applicant_cred_id
and
res.fk_hall_ticket_number=ah.hallticket_number
and
admit.applicant_credential_id=ad.applicant_cred_id
and 
pd.applicant_cred_id=admit.applicant_credential_id
and
caste.category_id=pd.category_id
and
pd.education_level_category_id=edu.education_level_category_id
and
qm.applicant_cred_id=pd.applicant_cred_id
and
ad.applicant_cred_id=qm.applicant_cred_id



group by
pd.registration_no, 
pd.date_of_birth,
pd.name,
pd.father_name,
pd.mother_name, 
pd.photo_identity_card_number,
pd.emailid_primary,
pd.applicant_cred_id,
pd.age_relaxation,
pd.validity_of_community_certificate,
pd.date_of_issue_community_certificate,
pd.photo_path,
pd.signature_path,
pd.community_certificate_path,
pd.photo_identity_path,
pd.photo_path,
ad.ncc_certificate_type,
ad.ncc_certificate_path,
res.sectioni_marks,
res.sectionii_marks,
res.sectioniii_marks,
res.sectioniv_marks,
res.sectionv_marks,
res.marks_relaxation_availed,
ah.hallticket_number,
admit.phase2_asc,
admit.phase2_test_date,
admit.chest_no,
admit.applicant_phase2_regno,
caste.category_long_code,
edu.education_level_category_id,
qm.aggregate_percentage,
qm.marksheet_path,
qm.certificate_number,
qm.date_of_issue_marksheet,
qm.education_level_id


order by pd.registration_no limit 5

0 个答案:

没有答案