You can do conditional aggregation :
select id,
sum(case when type="x" and location = 'L' then amount else 0 end) as sumofXandL,
. . .
from table t
group by id;
More Related Contents:
- What is the result of following SQL Query?
- Query SyntaxError [closed]
- PostgreSQL unnest() with element number
- SQL query to select dates between two dates
- is there an advantage to varchar(500) over varchar(8000)?
- Ms Access Query: Concatenating Rows through a query
- Database Design for Tagging [closed]
- How to avoid multiple function evals with the (func()).* syntax in a query?
- What is a Covered Index?
- Replacing NULL with 0 in a SQL server query
- How to connect to SQL Server from another computer?
- Equivalent of Oracle’s RowID in SQL Server
- Get the default values of table columns in Postgres?
- Months between two dates
- How do I use SQL’s GETDATE() and DATEADD() in a Linq to SQL expression?
- Why can’t I use alias in a count(*) “column” and reference it in a having clause?
- What are the benefits of using database cursor?
- What is semi-join in database?
- Detect overlapping date ranges from the same table
- How to find third or nᵗʰ maximum salary from salary table?
- sql group by only rows which are in sequence
- Generating random strings with T-SQL
- Custom Order in Oracle SQL
- How to select records without duplicate on just one field in SQL?
- Rowset does not support scrolling backward
- SQL Server SELECT INTO @variable?
- Select a column if other column is null
- How to subtract 30 days from the current date using SQL Server
- PostgreSQL: top n entries per item in same table
- How to do a case sensitive GROUP BY?