English 中文(简体)
页: 1 按条款分列的地理数据类别
原标题:SQL Geography data type column in GROUP BY clause

I m使用服务器,并制作一个文字,使工人的地理位置脱离我的数据库。 文字如下。

SELECT w.display_name, w.geo_location
FROM jobs j WITH(NOLOCK)
INNER JOIN workers w WITH(NOLOCK) ON w.worker_id = j.worker_id
WHERE .....

问题在于,由于有重复记录,我想在文字上添加,按批次编号:姓名、w.geo_ place。 加上一个数据类型地理的栏目,按条款将造成一个错误。

我补充说,这里的错误是:

“地貌”类型并不可比。 小组不能按条款加以使用。

是否有办法解决这一问题? 我不能将<代码>w.geo_position改为,因为地理数据类型需要。

最佳回答

您可使用<代码>row_ number() 类似内容。

declare @g geography;
set @g = geography::STGeomFromText( LINESTRING(-122.360 47.656, -122.343 47.656) , 4326);

declare @T table
(display_name varchar(10), geo_location geography)

insert into @T values ( 1 , @g)
insert into @T values ( 1 , @g)
insert into @T values ( 1 , @g)

insert into @T values ( 2 , @g)
insert into @T values ( 2 , @g)

select display_name, geo_location
from 
  (
    select *,
           row_number() over(partition by display_name, geo_location.ToString() order by (select 0)) as rn
    from @T
  ) as T
where rn = 1

结果:

display_name geo_location
------------ --------------------------------------------------------------------------------
1            0xE610000001148716D9CEF7D34740D7A3703D0A975EC08716D9CEF7D34740CBA145B6F3955EC0
2            0xE610000001148716D9CEF7D34740D7A3703D0A975EC08716D9CEF7D34740CBA145B6F3955EC0
问题回答

如果你想继续以星号使用该群,你可以将地球栏改为文字,并再次:

SELECT w.display_name, geography::STGeomFromText(w.geo_location.STAsText(), 4326) as Location
FROM jobs j WITH(NOLOCK)
INNER JOIN workers w WITH(NOLOCK) ON w.worker_id = j.worker_id
WHERE .....
GROUP BY w.display_name, w.geo_location.STAsText()




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

难以执行 REGEXP_SUBSTR

I m 查询Oracle 10g。 我有两张表格(样本数据见下文)。 i m 试图提取一些领域

SQL Query Shortcuts

What are some cool SQL shorthands that you know of? For example, something I learned today is you can specify to group by an index: SELECT col1, col2 FROM table GROUP BY 2 This will group by col2

PHP array callback functions for cleaning output

I have an array of output from a database. I am wondering what the cleanest way to filter the values is example array Array ( [0] => Array ( [title] => title 1 ...

OracleParameter and DBNull.Value

we have a table in an Oracle Database which contains a column with the type Char(3 Byte). Now we use a parameterized sql to select some rows with a DBNull.Value and it doesn t work: OracleCommand ...

Running numbers in SQL

I have a SQL-statement like this: SELECT name FROM users WHERE deleted = 0; How can i create a result set with a running number in the first row? So the result would look like this: 1 Name_1 2 ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签