'Hide same value in next line for the current column in SQL

From my SQL query, I get this output:

city Street housenumber flatnumber inhabitans
ACity AStreet 1 1 2
ACity AStreet 1 2 1
ACity AStreet 1 3 5
ACity AStreet 1 SUMFLAT 8
ACity AStreet 2 1 2
ACity AStreet 2 2 1
ACity AStreet 2 3 5
ACity AStreet 2 SUMFLAT 8
ACity AStreet SUMHOUSE 16
ACity BStreet ...

What I want is to remove the double entry in each row, so that it looks like this:

city Street housenumber flatnumber inhabitans
ACity AStreet 1 1 2
2 1
3 5
SUMFLAT 8
2 1 2
2 1
3 5
SUMFLAT 8
SUMHOUSE 16
BStreet ...

This is my current code:

SELECT 
    city, Street, housenumber, flatnumber, inhabitans
FROM   
    db

UNION

SELECT 
    city, Street, housenumber, 'SUMFLAT', SUM(inhabitans)
FROM 
    db
GROUP BY 
    city, street, housenumber

UNION

SELECT 
    city, Street, 'SUMHOUSE', '', SUM(inhabitans)
FROM
    db
GROUP BY 
    city, street
ORDER BY 
    city, Street, housenumber, flatnumber;

My questions are:

  • is this possible (without changing the order of the lines of the result table)
  • if possible in SQL : how?


Solution 1:[1]

You should not use that many unions in the query, instead simply get all data from database in to your page and using loop and conditions you can hide duplicate data also you can use html table rowspan for the same.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 N.S