Skip to content
Advertisement

How to aggregate values in rows based on condition and getting output in sql?

My table contains few rows, which has to be aggregated. eg: Columns are sites, fuel, sales, date when date ,sites and fuel is same I need to aggregate the sales column for those rows and have one row.( delete other rows or not to select those rows, since values are aggregated)

How can I do that simply in select query in sql?

eg

Output has to be;

My sql is like;

Advertisement

Answer

Use group by and sum() aggregation

As per your answer – you’ve to remove sales column from group by

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement