# 支援OData查詢語法

## OData語法

|       OData語法       |        說明        |                                                           範例                                                          |
| :-----------------: | :--------------: | :-------------------------------------------------------------------------------------------------------------------: |
|        format       | 資料格式json、xml、csv |                                           <p>回傳xml格式<br>$format=xml<br></p>                                           |
|        select       |     回傳資料的某些欄位    |                                          <p>回傳欄位1<br>$select= Field1<br></p>                                          |
|         top         |       取最前筆數      |                                              <p>取前10筆 <br>$top=10<br></p>                                             |
|         skip        |       跳過筆數       |                                            <p>跳過前100筆 <br>$skip=100<br></p>                                           |
|        filter       |   回傳符合特定表達式的資料   |                              <p>車牌號碼等於636-U7的資料<br>$filter=PlateNumb eq '636-U7'<br></p>                              |
|         date        |        日期        |                   <p>UpdateTime的日期格式為2015-09-17的資料<br>$filter=date(UpdateTime) eq 2015-09-17<br></p>                  |
|         time        |        時間        |                  <p>UpdateTime的時間格式為17:57:00+08:00的資料<br>$filter=time(UpdateTime) eq 11:59:48<br></p>                 |
|       contains      |        包含        |                              <p>車牌號碼包含FA的資料<br>$filter=contains(PlateNumb, 'FA')<br></p>                              |
|         all         |     所有項目都要符合     |            <p>針對停靠時間資料底下車站代碼，全部的車站代碼為1000的資料就回傳 <br> $filter=StopTimes/all(d:d/StationID eq '1000')<br></p>           |
|         any         |      其中一項符合      |            <p>針對停靠時間資料底下車站代碼，任一筆的車站代碼為1000的資料就回傳 <br>$filter=StopTimes/any(d:d/StationID eq '1000')<br></p>           |
| orderby {Field asc} |     針對某欄位作升冪     |                                      <p>針對欄位1作升冪<br>$orderby= Field1 asc<br></p>                                      |
| orderby{Field desc} |     針對某欄位作降冪     |                                      <p>針對欄位1作降冪<br>$orderby= Field1 desc<br></p>                                     |
|    spatialFilter    |     尋找附近點位資料     | <p>尋找: 緯度25.05463, 經度121.46584 ，範圍150 公尺內的資料<br>$spatialFilter=nearby(StopPosition, 25.05463, 121.46584, 150)<br></p> |

## 更多OData服務開發教學請詳見以下連結

[http://ptx.transportdata.tw/ptx/Download/公共運輸整合資訊平台資料服務開發實作.pdf](https://docs.google.com/viewer?url=https://github.com/ptxmotc/PTX_Web/blob/master/Swagger服務說明上傳參考檔案/公共運輸整合資訊平台資料服務開發實作.pdf?raw=true)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://motc-ptx-api-documentation.gitbook.io/motc-ptx-api-documentation/api-te-se/odata.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
