I'm trying to get a SQL query working that takes the total sales figures for a salesperson and uses that to extrude the address of the sales person to give me a 3D view of who is selling most. I have three tables; salepeople that has spid, an address table that has spaddressid and spgeom. And salestally that has the sales totals. Here is what I have so far;
CREATE TABLE sales_extruded AS SELECT sp.spid, ad.spaddressid, ST_Extrude(ad.spgeom, 0,0, st.saletallytotal) as the_geom, st.saletallytotal FROM public."address" ad, public."salestally" st, public."salespeople" sp WHERE st.spid = sp.spid ;
I would like to ask for help with two things; how to group all the sales figures for individual salespeople and how to test the geometry that is being created. I've brought the table into ArcMap but nothing is showing up. Ideally I'd like to bring it into ArcScene. Thanks to anyone who can help with this.
Without a schema, it's difficult to provide accurate and specific help, but here's an attempt. The first query would work if the salestally tables has one row for each salesperson. If you need to sum up values by sales person, you may need something like the second query, which sums the sales for a particular salesperson in the query at each address.
CREATE TABLE sales_extruded AS
SELECT sp.spid
, ad.spaddressid
, ST_Extrude(ad.spgeom, 0,0, st.saletallytotal) as the_geom
, st.saletallytotal
FROM public."address" ad
join public."salespeople" sp on sp.spaddressid = ad.spaddressid
join public."salestally" st on st.spid = sp.spid;
CREATE TABLE sales_extruded AS
SELECT sp.spid
, ad.spaddressid
, ST_Extrude(ad.spgeom, 0,0, sum(st.saletallytotal)) as the_geom
, sum(st.saletallytotal) as saletallytotal
FROM public."address" ad
join public."salespeople" sp on sp.spaddressid = ad.spaddressid
join public."salestally" st on st.spid = sp.spid
group by sp.spid, ad.spaddressid, ad.spgeom;