How can I prevent values from repeating in the 'From' and 'To' columns of my table? I want to display the data like this:
As you can see in the example above, instead of repeating 'XXXX' multiple times in the 'From' column, it appears only once. Same for 'YYYY' in the 'To' column. This creates a cleaner look where repeated values are merged into a single cell.
Currently, my table shows the same values repeated in every row. How can I achieve this merged cell effect?
with competitor as (
SELECT
DATE(timestamp) as date,
id_name as Competitor,
source_chain as Source,
destination_chain as Destination,
asset as Token,
transaction_amount as Amount,
AVG(fee_amount) as AVG_FEE
FROM `database.table_name`
WHERE {{Date}}
and {{From}}
and {{To}}
and {{Competitor}}
and {{Amount}}
and competitor != "COMPANY_A"
group by date, Competitor, Source, Destination, asset, transaction_amount
),
data AS (
SELECT
DATE(timestamp) as date,
'COMPANY_A' as Competitor,
source_chain as Source,
destination_chain as Destination,
asset as Token,
transaction_amount as Amount,
AVG(fee_amount) as AVG_FEE
FROM `database.table_name`
WHERE {{Date}}
AND {{From}}
AND {{To}}
AND {{Amount}}
AND id_name = "COMPANY_A"
GROUP BY date, Competitor, Source, Destination, Token, Amount
)
SELECT
c.*,
r.AVG_FEE as COMPANY_A_FEE,
(c.AVG_FEE - r.AVG_FEE) as FEE_DIFFERENCE,
ROUND(((c.AVG_FEE - r.AVG_FEE) / r.AVG_FEE), 2) as PERCENTAGE_DIFFERENCE
FROM competitor c
LEFT JOIN data r
ON c.date = r.date
AND c.Source = r.Source
AND c.Destination = r.Destination
AND c.Token = r.Token
AND c.Amount = r.Amount;