It's not at all clear how to get from your source data to your expected data as the data in the final table does not represent what was in your original.
However, as @0x01AA stated, you need to use a PIVOT at some point. There is a short tip here on CodeProject that gives a nice simple example:
Simple Way To Use Pivot In SQL Query[
^]
Here is an example of what you might want to do with your source data:
create table #demo (ID integer identity(1,1), Po varchar(10))
insert into #demo (Po) values
('A'), ('A'), ('A'), ('B'), ('A'), ('C'), ('D'), ('E')
SELECT *
FROM (
SELECT ID, Po
FROM #demo
) as s
PIVOT
(
COUNT(ID)
FOR [Po] IN (A, B, C, D, E)
)AS pvt
Which gives the results
A B C D E
4 1 1 1 1
If you want to do other stuff you might want to put this into a Common Table Expression (CTE) see
SQL Wizardry Part Three - Common Table Expressions (CTEs)[
^]
You also mentioned an auto-increment ID in your results. It is unlikely that this is going to be the ID from your table... a good way of getting a similar result in results is to use the
ROW_NUMBER[
^] function. Here is a trivial example using the same data as above:
SELECT ID, Po, ROW_NUMBER() OVER (ORDER BY ID DESC)
FROM #demo
ORDER BY ID
If I'm way off base with this just reply and I'll try to help further