Sql convert data into one row from multiple columns

I have a table

enter image description here

  • SQL Server: How to check if CLR is enabled?
  • Select primary key where max value in group clase SQL Server
  • How do I connect to SQL Server using OLEDB using Windows Authentication connection string
  • RODBC to connect to SQL Server on Mavericks
  • PDO MSSQL Server - Driver not found
  • Error when changing datatype of column in SQL Server DB - Java
  • and I want to convert it into one row for each customer number something like this:

    enter image description here

    Can someone point me to the right place , example where I can do similar thing.

    One Solution collect form web for “Sql convert data into one row from multiple columns”

    You need to use PIVOT. Something like the following query should help.

    SELECT CustomerNumber, 
        CASE WHEN [1] > 0 THEN 'Y' ELSE 'N' END [Sony],
        CASE WHEN [2] > 0 THEN 'Y' ELSE 'N' END [LG],
        CASE WHEN [3] > 0 THEN 'Y' ELSE 'N' END [Samsung]
    FROM
    (SELECT Product1, CustomerNumber
        FROM Table) AS SourceTable
    PIVOT
    (
        COUNT(Product1)
        FOR Product1 IN ([1], [2], [3])
    ) AS PivotTable;
    
    MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.