Oracle combines multiple rows of records for one row of instance analysis

Source: Internet
Author: User


1. Actual requirements: Description: in the preceding table, a student has multiple courses and scores, and now wants to have an SQL statement that combines the course name and score for display, www.2cto.com: all the courses and scores of this student are represented in one field, it includes all the course names and exam scores. 2. To solve the problem, you can use the function creation method to merge the two fields. However, this is too troublesome, because Oracle10g is used, the wmsys function can be used. wm_concat. 3. Solution SQL: the first step is to write a view view_ly_sjdxpt_jwcj and merge the two fields with the SQL code as select www.2cto.com xh hm and kcmc | zscj as kc_cj from dcuser. ly_xs_bzks_cjb B; Result: Write another view in step 2, and use wmsys. wm_concat () Merge the KC_CJ field into the SQL code: createorreplaceview_ly_sjdxpt_1_cj_kz as select hm, wmsys. wm_concat (kc_cj) as kccj from view_ly_sjdxpt_jwcj groupby hm; Result: You can use the SQL code: selectdistinct 'educational score 'dxlb, xh hm, (select lxdh fromdcuser. LY_XS_BZKS_XSJBXX where xh = B. xh) sjhm, to_char (sysdate, 'yyyymmddhh24mis') crsj, www.2cto.com xm | 'Dear Student, your score for each subject this semester is as follows:' | c. kccj as nr, ''bz,'' fssj fromdcuser. ly_xs_bzks_cjb B leftouterjoin dcuser_kz.view_ly_sjdxpt_1_cj_kz c on B. xh = c. hm result:
From the column wdh226

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.