Dynamic query crosstab chart generated by Oracle

Source: Internet
Author: User
Tags crosstab

Table Structure:

Serial number
Field Chinese name type description
1 ReportID NUMBER (4) Report No.
2 RecordNo NUMBER Record NUMBER
3 FieldNo NUMBER (2) field NUMBER
4 Datum VarChar (200) Value

1 1 1 Wang Xiaoqiang
1 1 2 Wangjia Road, Jianghan district, Wuhan
1 1 3 2010-01-12
1 1 4 65783213
1 1 5 NO
1 2 1 Liu chapter
1 2 Wuchang District Zhongnan Road
1 2 3 1950-04-12
1 2 4 13999999999
1 2 5 married

Dynamic query crosstab chart generated by Oracle

Select max (a1) as name, max (a2) as address, max (a3) as birth, max (a4) as phone, max (a5) as marital status

From (select recordno,

Nvl (decode (fieldno, 1, Datum), '') a1,

Nvl (decode (fieldno, 2, Datum), '') a2,

Nvl (decode (fieldno, 3, Datum), '') a3,

Nvl (decode (fieldno, 4, Datum), '') a4,

Nvl (decode (fieldno, 5, Datum), '') a5

From Rep_Register

Where reportid = 1

And RecordNo = (select RecordNo

From Rep_Register

Where FieldNo = 2

And Datum Like 'wuhan % '))

Group by recordno

Reportid = 1 is the report number to be queried

The following are other query conditions:

Related Article

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.