on 04-12-2021 2:46 PM
Hello everyone,
I'm trying to find a way to calculate distance for each value from table A for each value from table B. I've got my ST_POINT calculated in table A (POINT) and B (ROUTE_POINT). Following statement allows me to calculate the distance between all records from table A and ONLY one value from table B as I need to use the WHERE clause: (note: ROUTE ID = key value which represents each coordinate from table B)
SELECT DISTINCT POINT.ST_Distance((SELECT DISTINCT POINT FROM "xxxx"."ROUTE_POINT" WHERE ROUTE_ID =4), 'meter') AS DISTANCE FROM "xxxx"."A";
when I get rid of the WHERE clause I receive following error message:
SAP DBTech JDBC: [305]: single-row query returns more than one row
I was also thinking about the cross join where all values from both tables are combined, but whould it be to complicated, wouldn't? Do I need a procedure in my case or is there any simplier way to solve it?
Thank you in advance!
Something like
SELECT "A"."POINT".ST_Distance("B"."POINT", 'meter') AS "DISTANCE"
FROM "A", "B";
should give you a cross-join between all rows or "A" and "B" tables.
Example:
CREATE TABLE A (ID int, POINT ST_POINT);
CREATE TABLE B (ID int, POINT ST_POINT);
INSERT INTO "A" VALUES(1, new st_point(-1,-1));
INSERT INTO "A" VALUES(2, new st_point(-1, 0));
INSERT INTO "A" VALUES(3, new st_point(-1, 1));
INSERT INTO "B" VALUES(1, new st_point( 1,-1));
INSERT INTO "B" VALUES(2, new st_point( 1, 0));
INSERT INTO "B" VALUES(3, new st_point( 1, 1));
SELECT "A"."POINT".ST_asWKT() AS "A",
"B"."POINT".ST_asWKT() AS "B",
"A"."POINT".ST_Distance("B"."POINT", 'meter') AS "DISTANCE"
FROM "A", "B";
Pozdrawiam,
-Witalij
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
From what you describe, it is a cross join query. Not sure why you had Distinct in your query (two places)? If this is a Transportation Management calculation, you might be better to use the tools TM provides instead of doing it with a HANA DB query.
Cheers, Mike
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.