Solutions to some problems in the DB2 database (1)

Source: Internet
Author: User

In the process of using the DB2 database, some problems are inevitable. This article summarizes several common DB2 database problems for your reference.

1. Use SQL to implement cross tabulation.

SQL Server provides the limit keyword to help implement cross-tabulation, but DB2 does not seem to have an equivalent value. The implementation method is slightly more complex. The following is an example.

SELECT location,
MAX (case when metric = 'ph' THEN value END) as PH,
MAX (case when metric = 'Hg 'THEN value END) as Hg,
MAX (case when metric = 'fe 'THEN value END) as Fe,
MAX (case when metric = 'mn 'THEN value END) as Mn
FROM data_view
Group by location

The data_view table/view has three fields: location, metric, and value. The data is as follows:

Location1 PH 1.142575278063135
Location1 Hg 0.0018310994140037379.
Location1 Fe 0.2974983113601452
Fig 1 Mn 0.09548843270448454
Location2 PH 6.096025515217242
Location2 Hg 0.005575948698159294
Location2 Fe 0.32657056877142043
Location2 Mn 0.009418315198912612
The resulting crosstab chart:

Location ph Hg Fe Mn
Location1 1.142575278063135 0.0018310994140037379 0.2974983113601452
Location2 6.096025515217242 0.005575948698159294 0.32657056877142043


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.