Changes between Version 60 and Version 61 of CLC Join


Ignore:
Timestamp:
Jun 1, 2010 3:33:42 PM (15 years ago)
Author:
cedric
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • CLC Join

    v60 v61  
    146146         * seawater_52 
    147147 
    148 Importantly this request will provide repeated lines with the same content it is this necessary to add a ''' DISTINCT ON ''' clause. 
    149  
    150 {{{ 
    151 #!sql 
    152 SELECT gid,code_00, id,round(area) as area FROM clc.clipped_Bretagne1 order by gid, code_00 limit 10; 
    153 -- here I'm keeping the surface so that we will b able to calculate for any basin 
    154 -- or group of basins a percentage of surface according to the basin surface 
     148Importantly this request will provide repeated lines with the same content it is this necessary to add a ''' DISTINCT ON ''' clause. I had forgotten to include the sum() and group by clause, for instance urban will correspond to the sum of lines whith code_00 111 112 121 122 123 124 131 132 133.  
     149 
     150{{{ 
     151#!sql 
     152 
    155153DROP TABLE IF EXISTS clc.surf_area; 
    156154CREATE TABLE clc.surf_area AS ( 
     
    170168         FROM ( 
    171169        SELECT  gid from clc.clipped_bretagne1  ) as init         
    172         FULL OUTER JOIN (SELECT gid,area AS urban_11_13,code_00 FROM clc.clipped_bretagne1 WHERE  
     170        FULL OUTER JOIN (SELECT gid,sum(area) AS urban_11_13 FROM clc.clipped_bretagne1 WHERE  
    173171                        substring(code_00 from 1 for 2)='11'  
    174172                        OR  substring(code_00 from 1 for 2)='12' 
    175                         OR substring(code_00 from 1 for 2)='13' ) AS urban 
     173                        OR substring(code_00 from 1 for 2)='13'  
     174                        GROUP BY gid) AS urban 
    176175                       on (init.gid) =(urban.gid)                
    177         FULL OUTER JOIN (SELECT gid,area AS green_urban_14,code_00  FROM clc.clipped_bretagne1 WHERE  
    178                         substring(code_00 from 1 for 2)='14') AS green_urban 
     176        FULL OUTER JOIN (SELECT gid,sum(area) AS green_urban_14 FROM clc.clipped_bretagne1 WHERE  
     177                        substring(code_00 from 1 for 2)='14' 
     178                        GROUP BY gid) AS green_urban 
    179179                        on green_urban.gid =init.gid 
    180         FULL OUTER JOIN (SELECT gid,area AS arable_land_21,code_00   FROM clc.clipped_bretagne1 WHERE  
    181                         substring(code_00 from 1 for 2)='21') AS arable_land 
     180        FULL OUTER JOIN (SELECT gid,sum(area) AS arable_land_21 FROM clc.clipped_bretagne1 WHERE  
     181                        substring(code_00 from 1 for 2)='21' 
     182                        GROUP BY gid) AS arable_land 
    182183                        on arable_land.gid =init.gid 
    183         FULL OUTER JOIN (SELECT gid,area AS plantations_22, code_00  FROM clc.clipped_bretagne1 WHERE  
    184                         substring(code_00 from 1 for 2)='22') AS plantations 
     184        FULL OUTER JOIN (SELECT gid, sum(area) AS plantations_22 FROM clc.clipped_bretagne1 WHERE  
     185                        substring(code_00 from 1 for 2)='22' 
     186                        GROUP BY gid) AS plantations 
    185187                        on plantations.gid =init.gid 
    186         FULL OUTER JOIN (SELECT gid,area AS pastures_23 ,code_00 FROM clc.clipped_bretagne1 WHERE  
    187                         substring(code_00 from 1 for 2)='23') AS pastures 
     188        FULL OUTER JOIN (SELECT gid,sum(area) AS pastures_23 FROM clc.clipped_bretagne1 WHERE  
     189                        substring(code_00 from 1 for 2)='23' 
     190                        GROUP BY gid) AS pastures 
    188191                        on pastures.gid =init.gid 
    189         FULL OUTER JOIN (SELECT gid,area AS crops_natural_24 ,code_00  FROM clc.clipped_bretagne1 WHERE  
    190                         substring(code_00 from 1 for 2)='24') AS crops_natural 
     192        FULL OUTER JOIN (SELECT gid, sum(area) AS crops_natural_24 FROM clc.clipped_bretagne1 WHERE  
     193                        substring(code_00 from 1 for 2)='24' 
     194                        GROUP BY gid) AS crops_natural 
    191195                        on crops_natural.gid =init.gid 
    192         FULL OUTER JOIN (SELECT gid,area AS forest_31,code_00   FROM clc.clipped_bretagne1 WHERE  
    193                         substring(code_00 from 1 for 2)='31') AS forest 
    194                         on forest.gid =init.gid 
    195         FULL OUTER JOIN (SELECT gid,area AS natural_32_33 ,code_00  FROM clc.clipped_bretagne1 WHERE  
     196        FULL OUTER JOIN (SELECT gid,sum(area) AS forest_31 FROM clc.clipped_bretagne1 WHERE  
     197                        substring(code_00 from 1 for 2)='31' 
     198                        GROUP BY gid) AS forest 
     199                        ON forest.gid =init.gid 
     200        FULL OUTER JOIN (SELECT gid,sum(area) AS natural_32_33 FROM clc.clipped_bretagne1 WHERE  
    196201                        substring(code_00 from 1 for 2)='32' 
    197                         OR  substring(code_00 from 1 for 2)='33') AS nature 
    198                         on nature.gid =init.gid 
    199         FULL OUTER JOIN (SELECT gid,area AS wetlands_4 ,code_00  FROM clc.clipped_bretagne1 WHERE  
    200                         substring(code_00 from 1 for 1)='4') AS wetlands 
     202                        OR  substring(code_00 from 1 for 2)='33' 
     203                        GROUP BY gid) AS nature 
     204                        ON nature.gid =init.gid 
     205        FULL OUTER JOIN (SELECT gid, sum(area) AS wetlands_4  FROM clc.clipped_bretagne1 WHERE  
     206                        substring(code_00 from 1 for 1)='4' 
     207                        GROUP BY gid) AS wetlands 
    201208                        on wetlands.gid =init.gid 
    202         FULL OUTER JOIN (SELECT gid,area AS water_51 ,code_00  FROM clc.clipped_bretagne1 WHERE  
    203                         substring(code_00 from 1 for 2)='51') AS waterbodies 
     209        FULL OUTER JOIN (SELECT gid,sum(area) AS water_51 FROM clc.clipped_bretagne1 WHERE  
     210                        substring(code_00 from 1 for 2)='51' 
     211                        GROUP BY gid) AS waterbodies 
    204212                        on waterbodies.gid =init.gid 
    205         FULL OUTER JOIN (SELECT gid,area AS seawater_52 ,code_00  FROM clc.clipped_bretagne1 WHERE  
    206                         substring(code_00 from 1 for 2)='52') AS seawater 
     213        FULL OUTER JOIN (SELECT gid,sum(area) AS seawater_52 FROM clc.clipped_bretagne1 WHERE  
     214                        substring(code_00 from 1 for 2)='52' 
     215                        GROUP BY gid) AS seawater 
    207216                        on seawater.gid =init.gid); --375 ms 
    208 ALTER TABLE clc.surf_area ADD CONSTRAINT c_pk_gid_surf_area PRIMARY KEY (gid); 
    209217}}} 
    210218{{{