简体   繁体   中英

How to make a SQL query to display two columns values to one column?

I have a table structure like that as shown below. I want to show names under parent of names (where parent is ledger group)

我期望像这样的结果

图片1

DECLARE @t1 TABLE
(
 ParentGroup varchar(20),
 LedgerName varchar(20),
 TotalDebit float,
 credit float
)

INSERT INTO @t1
SELECT *
  FROM Table1

INSERT INTO @t1
SELECT Distinct ParentGroup, ParentGroup, NULL, NULL
  FROM Table1

Select LedgerName, TotalDebit, credit from @t1
group by LedgerName, TotalDebit, credit
ORDER BY (CASE WHEN TotalDebit IS NULL THEN 0 ELSE TotalDebit END)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM