OrientDB - 函数



本章解释了 OrientDB 中不同类型函数的完整参考。下表定义了函数列表,按其功能分类。

图函数

尝试一些图函数以及以下查询。

执行以下查询以获取所有车辆顶点的所有输出顶点。

orientdb {db = demo}>SELECT out() from Vehicle

如果以上查询成功执行,您将获得以下输出。

---+----------+--------- 
 # | @class   | out 
---+----------+--------- 
 0 | Vehicle  | #11:2 
 1 | Vehicle  | #13:1 
 2 | Vehicle  | #13:4 
---+----------+--------- 

执行以下查询以获取顶点 #11:3 的输入和输出顶点。

orientdb {db = demo}>SELECT both() FROM #11:3 

如果以上查询成功执行,您将获得以下输出。

---+----------+--------+------- 
 # | @class   | out    | in  
---+----------+--------+------- 
 0 | Vehicle  | #13:2  | #10:2   
 ---+----------+-------+-------

数学函数

尝试使用以下查询的一些数学函数。

执行以下查询以获取所有员工的薪资总和。

orientdb {db = demo}>SELECT SUM(salary) FROM Employee 

如果以上查询成功执行,您将获得以下输出。

---+----------+--------- 
 # | @CLASS   | sum 
---+----------+--------- 
 0 | null     | 150000 
---+----------+---------

执行以下查询以获取所有员工的平均薪资。

orientdb {db = demo}>SELECT avg(salary) FROM Employee

如果以上查询成功执行,您将获得以下输出。

---+----------+--------- 
 # | @CLASS   | avg 
---+----------+--------- 
 0 | null     | 25 
---+----------+--------- 

集合函数

尝试使用以下查询的一些集合函数。

执行以下查询以获取教授九年级课程的教师集合。

orientdb {db = demo}>SELECT ID, set(teacher.id) AS teacherID from classess where class_id = 9 

如果以上查询成功执行,您将获得以下输出。

---+----------+--------+-------------------------- 
 # | @CLASS   | id     | TeacherID 
---+----------+--------+-------------------------- 
 0 | null     | 9     |   1201, 1202, 1205, 1208 
---+----------+-------+---------------------------

其他函数

使用以下查询尝试一些杂项函数。

执行以下查询以了解如何执行 if 表达式。

orientdb {db = demo}> SELECT if(eval("name = 'satish'"), "My name is satish", 
"My name is not satish") FROM Employee

如果以上查询成功执行,您将获得以下输出。

----+--------+----------------------- 
#   |@CLASS  | IF 
----+--------+----------------------- 
0   |null    |My name is satish  
1   |null    |My name is not satish 
2   |null    |My name is not satish  
3   |null    |My name is not satish  
4   |null    |My name is not satish  
----+--------+------------------------ 

执行以下查询以获取系统日期。

orientdb {db = demo}> SELECT SYSDATE() FROM Employee

如果以上查询成功执行,您将获得以下输出。

----+--------+----------------------- 
#   |@CLASS  | SYSDATE 
----+--------+----------------------- 
0   |null    |2016-02-10 12:05:06 
1   |null    |2016-02-10 12:05:06 
2   |null    |2016-02-10 12:05:06 
3   |null    |2016-02-10 12:05:06 
4   |null    |2016-02-10 12:05:06 
----+--------+------------------------ 

通过彻底使用此函数,您可以轻松地操作 OrientDB 数据。

广告

© . All rights reserved.