Read data from the three associated data tables

xiaoxiao2021-03-06  73

There are three data sheets:

Table 1 Table 2 Table 3 ID (primary key) ID (primary key) Id (primary key) Animal Tab1ID (Table 1 Primary key) Tab2ID (Table 2 Primary Key) TYPE NAME

How to use a SQL statement to achieve the following reading mode:

Animal1 Type1 Name1 Name2 Name3 Type2 Name4 Type3 Name5 Name6animal2 Type4 Name7 Name8 Name9 Type5 Name10 Name11 Name12 Type6 Name13 Name14 Name15 Name16 Name17 .........

Workaround: Select Oid, Name, Type from (SELECT A.OID || B.Oid || C.Oid Col, '|| C.ItemName Name, C.Oid OID,' 1 'Type from LZ_LAW A, LZ_LAWCHAPTER B, LZ_LAWITEM C where a.oid = B.lawide and b.oid = c.chapteroid Union All Select a.Oid || B.Oid Col, '' || B.Chapname Name, B.Oid OID, '2' Type from lz_law a, lz_lawchapter b where a.oid = B.lawoid Union All Select A.Oid Col, a.lawname name, a.oid Oid, '3' Type from lz_law a) T ORDER BY COL Note: In this SQL There are two space string plus field values ​​for indentation; if it is used in B / S, the space here should be the full-corner space of Chinese characters. Thanks here: BZSZP (Songzip)

转载请注明原文地址:https://www.9cbs.com/read-93383.html

New Post(0)