how to detect polygons within other (many) polygons in postgis - postgis

I have two datasets: 1. ZipCodes and 2. Neighborhoods (think of them as like counties).
I want to join each neighborhood with which zipcodes cover it. Most neighborhoods will only be within one zipcode, but in some cases neighborhoods will straddle two. So for example:
Neighborhood 1 is inside 20001
Neighborhood 2 is inside 20002
Neighborhood 3 is inside 20001,20002
Here is what I have so far:
SELECT name, zipcode
FROM
neighborhood_names nn, dc_zipcode_boundries dzb
WHERE ST_Intersects(nn.the_geom, dzb.the_geom);
Note: Updated to within based on comments, now getting an answer for each neighborhood but still not able to get the Array function to respond as expected.

I figured it out. thanks to the help from John. My statement needed a group by (whcih is what the error said, just needed some time to digest before it clicked).
the snippet below worked for anyone following
SELECT name, array_to_string(array_agg(zipcode), ',')
FROM
neighborhood_names nn, dc_zipcode_boundries dzb
WHERE ST_Intersects(nn.the_geom, dzb.the_geom)
group by name

Related

SalesForce SOQL highest number from size column

i'm new to SOQL and SF, so bear with me :)
I have Sales_Manager__c object tied to Rent__c via Master-Detail relationship. What i need is to get Manager with highest number of Rent deals for a current year. I figured out that the Rents__r.size column stores that info. The question is how can i gain access to the size column and retrieve highest number out of it?
Here is the picture of query i have
My SOQL code
SELECT (SELECT Id FROM Rents__r WHERE StartDate__c=THIS_YEAR) FROM Sales_Manager__c
Try other way around, by starting the query from Rents and then going "up". This will let you sort by the count and stop after say top 5 men (your way would give you list of all managers, some with rents, some without and then what, you'd have to manually go through the list and find the max).
SELECT Manager__c, Manager__r.Name, COUNT(Id)
FROM Rent__c
WHERE StartDate__c=THIS_YEAR
GROUP BY Manager__c, Manager__r.Name
ORDER BY COUNT(Id) DESC
LIMIT 10
(I'm not sure if Manager__c is the right name for your field, experiment a bit)

Access 2007 Combobox displaying wrong results from table

I have four ComboBoxes that are linked to SQL Tables and then they are linked to a log table.
The problem I have is that the combobox is displaying the correct options but only logging the ID value.
So say I have a combobox called Location and it has 3 locations:
Cape Town
Dallas
London
The ComboBox is showing those 3 choices in the drop down but when the choice is logged it will only return the values 1,2 or 3 and not the cities
Here is the row source:
SELECT Location.ID, Location.Location FROM Location ORDER BY Location.ID, Location.Location;
But when I tried swapping the Location and ID order around it then displays the values and then logs the cities.
Also this is only an issue since I linked the tables to SQL when they were local tables it worked fine.
I must be missing some sort of search field in the source query, can anyone help me please
Thanks
Dan
I managed to solve it, I had to take ID out of the equation completely and then add into extra location columns in my row source
It ended up like this:
SELECT Location.Location, Location.Location, Location.Location FROM Location ORDER BY Location.Location;
To be honest, I stumbled across this and it works. So that will do for me!

SSRS Cumulative Running Values

So I am attempting to reorganize a report I put together. I had the running totals working before the redesign, but I have been pouring over this for a day and can't figure out why it is no longer functioning as I had thought.
The sum values are correct here, but it keeps accumulating them and not spreading them out over the area paths I've defined (which are populating obviously).
I have the sprint and area name linked in a hierarchy for the row groups then followed by this expression:
=RunningValue(Fields!Sev_1_Count.Value, SUM, "RowGroup")
Each column after the area name is defining a severity level of defects, just for context. The Sev_1_Count expression should take the count of all defects in this severity level then spread them across their associated area names. Which worked in the previous version... I just can't for the life of me figure why it won't work now. Thoughts?
I think the problem is that you're applying the running total to each field. It seems that wherever you're putting
RunningValue(Fields!Sev_1_Count.Value, SUM, "RowGroup")
you should just have
Fields!Sev_1_Count.Value
instead. As you need totals on both sides, you should have a matrix and the right and bottom rows of you columns should be outside the group "Iteration Name" with a value of
sum(Fields!Sev_1_Count.Value).
Not sure what I'm missing. Maybe your original dataset is set up in a way where you can't do that?
Your row groups should be grouped on name and your column groups should be grouped on severity level.
I'm not sure what you mean by your comment below Randy, but the best practice for something like this would be to have a data-set that consists of 3 fields:
"EnvironmentName", "DefectCount" and "SeverityLevel". Then in your matrix, you have the DefectCount as your Details, EnvironmentName as your RowGroup and SeverityLevel as your ColumnGroup. Then the right column and bottom row are placed outside the groups and have the value of Sum(DefectCount). Anything outside of that seems like an over-complication.
It seems like you want to use running total to add the columns for severity levels if i'm not mistaken? then you shouldn't be grouping them on rows. Instead of the "RowGroup" scope, maybe you should try None. Good luck.

SSRS Matrix - one value/row Adjacent?

I have a problem that I have been trying to solve... I Think it is fairly easy but I am new to SSRS. I have made a matrix showing the values of 2 different columns per country on one row. However I want to show only 1 value per row, that means that each country should get 2 rows each.
I Think it has something to do with adjacent but I can't get it right :(
At the moment it looks like this:
France 10 20
But I want it to look like this (don't the dashes...):
France 10
France --- 20
I think this should be possible to do without coding, I just can't find the right property/or Tablix function.
Is there anyone out there who can help me?
Change your data source so that it splits the rows. So for example:
select Country, Value1
From CountryTable
Union All
Select Country, Value2
From CountryTable
You will have to consider your sorting to make sure that your rows are aligned how you need them.
This feels like a weird requirement. But, setting the Row Grouping to Country and then Value should achieve this if I'm understanding your data structure properly.

how to know how many times its a value in the databes? and for all values?

This can be aplied to tags, to coments, ...
My question its to obtain for example, top 20 repetitions for an atribute in a table..
I mean, i know i can ask for a selected atribute with the mysql_num_rows, but how do i do it to know all of them?
For example,
Most popular colors:
Red -100000
blue -5000
white -200
and so on...
if anyone can give me a clue.. thanks!
SELECT `name`, count(*) as `count` FROM `colors`
GROUP BY `name`
ORDER BY `count` DESC
You want to do this computation on the database, not in your application. Usually, a query of the following form should be fine:
SELECT color_id, COUNT(product_id) AS number
FROM products
GROUP BY color_id
ORDER BY number DESC
LIMIT 20
It will be faster this way, as only the value-count data will be sent from the database to the application. Also, if you have indices set up correctly (on color_id, for instance), thighs will be smoother.

Resources