在 sql 的不同列中分别显示一个 table 的数据

separately show data from one table in different column in sql

我想要这个 table 的输出,如下所示

  Lslno                head                            Amount 
  -----                ----                            ------
  I0001             Sales(S001)                       20000.00
  I0002             Debters(D001)                     30000.00
  I0003             Loan(L001)                        5000.00
  I0004             Capital(c001)                     6000.00
  E0001             Creditors(CRD001)                 2000.00
  E0002             Expenses(EX001)                   3000.00
  E0003             PaymentForPurchase(PP001)         4000.00
  E0004             PurchasingFixedAsset(PFA001)      10000.00

输出-

   Lslno     head            Amount   Lslno   head                            amount
   -----     ----           ------    -----   ------                         --------
   I0001    Sales(S001)     20000.00  E0001 Creditors(CRD001)               2000.00
   I0002    Debters(D001)   30000.00  E0002 Expenses(EX001)                 3000.00 
   I0003    Loan(L001)      5000.00   E0003 PaymentForPurchase(PP001)       4000.00 
   I0004    Capital(C001)   6000.00   E0004 PurchasingFixedAsset(PFA001)    10000.00

只需使用适当的过滤器将 table 加入自身。

SELECT 
  t1.*, t2.*
FROM tbl AS t1
  JOIN tbl AS t2 ON SUBSTRING(t1.LslNo, 2, 4) = SUBSTRING(t2.LslNo, 2, 4)
WHERE t1.Lslno LIKE 'I%'
  AND t2.Lslno LIKE 'E%'