English 中文(简体)
问题:选择城市距离而不重复
原标题:SQL Question: select cities distance without duplicates

我有一栏:城市、x、 y

I need to select the distance between all the cities without duplications the results should look like this city1,city2,distance

but I shouldn t get city2,city1,distance ( since I already got the distance between those cities...

what is the correct SQL query for that... thanks!

最佳回答
SELECT c1.City, c2.City, dbo.CalcDistance(c1.x, c1.y, c2.x, c2.y)
FROM Cities c1, Cities c2
WHERE c1.CityID > c2.CityID 
问题回答
SELECT
    C1.city,
    C2.city,
    <distance calculation>
FROM
    Cities C1
INNER JOIN Cities C2 ON
    C2.city_id > C1.city_id

我留下了距离计算空白之处,因为它取决于你是否重新“作为代管地”,使用街道路线,核算地球的 cur。

你试图做的是所谓的“总开支”。

与三角合作谨慎,如<代码>ON c1.CityID > c2.CityID,它们制造了一个 car产品! (我不想与任何其他人争辩。)

Have a look at Jeff Moden s world best article about running totals: Solving the "Running Total" & "Ordinal Rank" Problems (Rewritten).

如果你没有的话,你就不得不做一个说明(只需要一个电子邮件地址)。 然而,我承诺这样做是值得的。





相关问题
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: ...

热门标签