簡體   English   中英

如何使mysql查詢該案例

[英]how make mysql query for that case

我讓我的真實案例更簡單。

案子:

它們以點的形式傳遞多條曲線,每條曲線都有最終的1點。最后一點在數據庫中表示為曲線的最大point_order值。

應該找到在特定點傳遞並具有相同最終點的曲線(相同的point_id)

案例(表格):

點表:

point_id|x|y

編輯:

curve_points表示例 - 查找具有相同point_id = 80和相同最終點的所有曲線:

id|curve_id|point_id|point_order
  |119     |6       |12
  |119     |80      |9
  |119     |1000    |1
  |76      |80      |7
  |76      |6       |9
  |76      |2       |2
  |90      |80      |7
  |90      |6       |9
  |90      |99      |15

輸出結果應為:

  |curve_id|
  |119     | 
  |76      |

因為曲線119,76具有相同的最終點= 6並且具有相同的點80.曲線90不是因為點6不是他的最終點

psedocode函數 - 需要添加代碼以選擇相同的最終點

function findCurvesForSamePointAndSameFinalPoint(pointID){
    query="SELECT curve_id FROM curve INNER JOIN point GROUP BY curve_id HAVING point_id="+pointID+";";
    return getDATABASEResult(query);  
}

Edit2:在線sql用一些數據來測試: http ://sqlfiddle.com/#!2/59e9f/1(現有的查詢沒有用)

謝謝

如果我做對了 它是這樣的:

SQLFiddle演示

select distinct c1.curve_id,(select point_id from curve t1
       where t1.curve_id=c1.curve_id 
       order by point_order desc 
       limit 1)
TheLastPoint

from curve c1
join curve c2 on
(select point_id from curve t1
       where t1.curve_id=c1.curve_id 
       order by point_order desc 
       limit 1)
=
(select point_id from curve t2 
       where t2.curve_id=c2.curve_id 
       order by point_order desc 
       limit 1)
And c1.curve_id<>c2.curve_id

where c1.curve_id in (select curve_id from curve where point_id=80)
      and 
      c2.curve_id in (select curve_id from curve where point_id=80)
order by TheLastPoint,c1.curve_id

首先我想問一下,Curve表是如何與點表創建關系的? 必須有REDUNDANT Curve_ids才能使用Point表映射它們。

如果可以更改數據庫結構,則可以使用MySQL Geometry ,它具有PointCurve等類。 您可以使用內置功能檢查兩條曲線是否交叉以及更多曲線。

我發現這個相關。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM