SQL statement syntax for changing columns in the SQL Server database:
How to calculate the area:
Select lznd,
Sum (case when lzfs = 'lease 'Then isnull (jflzmjm, 0) + isnull (yflzmjm, 0) else 0 end) as mjm_cz,
Sum (case when lzfs = 'shareholding 'Then isnull (jflzmjm, 0) + isnull (yflzmjm, 0) else 0 end) as mjm_rg,
Sum (case when lzfs = 'subcontracting 'Then isnull (jflzmjm, 0) + isnull (yflzmjm, 0) else 0 end) as mjm_zb,
Sum (case when lzfs = 'transfer' then isnull (jflzmjm, 0) + isnull (yflzmjm, 0) else 0 end) as mjm_zr,
Sum (case when lzfs = 'interval' then isnull (jflzmjm, 0) + isnull (yflzmjm, 0) else 0 end) as mjm_hh,
Sum (case when lzfs = 'others' isnull (jflzmjm, 0) + isnull (yflzmjm, 0) else 0 end) as mjm_qt
From lz_ht_base
Group by lznd
How to calculate the number:
Select lznd,
Sum (case when lzfs = 'lease 'Then 1 else 0 end) as gs_cz,
Sum (case when lzfs = 'shareholding 'Then 1 else 0 end) as gs_rg,
Sum (case when lzfs = 'subcontracting 'Then 1 else 0 end) as gs_zb,
Sum (case when lzfs = 'transfer 'then 1 else 0 end) as gs_zr,
Sum (case when lzfs = 'interval' then 1 else 0 end) as gs_hh,
Sum (case when lzfs = 'others' 1 else 0 end) as gs_qt
From lz_ht_base
Group by lznd
Select lznd, lzfs from lz_ht_base
---- The --- end ----