I have following table (SQL Server) Table name is LandParcels
Blockid ParcelNo Stateorprivate
========================
11001901 30 Deemana
11001901 35 Deemana
11001901 41 State
11001901 45 State
11001901 110 Private
11001901 111 Private
11001902 1 Deemana
11001902 11 State
11001902 16 Private
11002001 15 Deemana
11002001 16 State
11003001 20 Private
11002003 2 Deemana
11002003 3 State
11003003 4 Private
Blockid (Numeric) = first 6 digits used for Cadastral Map No and last 2 digits for the Block No
eg: 110019 is Cadastal map no and 01 is Block No.
I used the following query
select substring(ltrim(str(blockid)),1,6) as blockid,stateorprivate, count(*) as noofLP from LandParcels group by blockid, stateorprivate order by blockid asc
Result is
Blockid Stateorprivate noofLP
========================
110019 Deemana 2
110019 State 2
110019 Private 2
110019 Deemana 1
110019 State 1
110019 Private 1
110020 Deemana 1
110020 State 1
110020 Private 1
110020 Deemana 1
110020 State 1
110020 Private 1
I want to get the following result for a report
blockid noofBlocks Deemana State Private Amt_of_Deemana_State_Private
110019 2 3 3 3 9
110020 2 2 2 2 6
How to query this. Pl help me.