MySQL 中的光标表达式
Cursor expression in MySQL
如何实现与 Oracle 游标表达式在 MySQL 数据库(从 5.6 开始的版本)中相同的效果
下面是 Oracle 游标表达式的示例查询
SELECT department_name, CURSOR(SELECT salary, commission_pct
FROM employees e
WHERE e.department_id = d.department_id)
FROM departments d;
如何使用 MySQL 数据库实现与此相同的目的?
如果我在 oracle 上执行此查询,将生成以下输出,
depart_name游标结果
MCA { < SALARY=20000 , COMMISSION_PCT=2 > , < SALARY=40000,COMMISSION_PCT=20> ,}
BE {< SALARY=20000,COMMISSION_PCT=2 >,}
我不知道 CURSOR() 在 oracle 中做了什么,因为我从未接触过 oracle,但我不知道它是否对你有帮助,但我认为你想这样加入:
SELECT d.department_name, e.salary, e.commission_pct.
FROM departments d
INNER JOIN employees e
ON (e.department_id = d.department_id);
我给你这个 link 有关关节的更多信息:
https://sql.sh/cours/jointures
并根据 sql.sh:
There are several methods to associate 2 tables together. Here is the
list of the different techniques that are used:
- INNER JOIN: internal join to return the records when the condition is true in both tables. This is one of the most common
joins.
- CROSS JOIN: cross join to make the Cartesian product of 2 tables. In other words, allows to join each row of a table with each
row of a second table. Attention, the number of results is
generally very high.
- LEFT JOIN (or LEFT OUTER JOIN): external join to return all the records of the left table (LEFT = left) even if the condition is not
checked in the other table.
- RIGHT JOIN (or RIGHT OUTER JOIN): External join to return all records in the right-hand table (RIGHT = right) even if the condition
is not checked in the other table.
- FULL JOIN (or FULL OUTER JOIN) : external join to return the results when the condition is true in at least one of the 2 tables.
- SELF JOIN : allows to join a table with itself as if it were another table.
- NATURAL JOIN : natural join between 2 tables if there is at least one column with the same name between the 2 SQL tables.
- UNION JOIN: joint of union.
如果您有任何问题,我可以回答。
如何实现与 Oracle 游标表达式在 MySQL 数据库(从 5.6 开始的版本)中相同的效果 下面是 Oracle 游标表达式的示例查询
SELECT department_name, CURSOR(SELECT salary, commission_pct
FROM employees e
WHERE e.department_id = d.department_id)
FROM departments d;
如何使用 MySQL 数据库实现与此相同的目的?
如果我在 oracle 上执行此查询,将生成以下输出, depart_name游标结果
MCA { < SALARY=20000 , COMMISSION_PCT=2 > , < SALARY=40000,COMMISSION_PCT=20> ,}
BE {< SALARY=20000,COMMISSION_PCT=2 >,}
我不知道 CURSOR() 在 oracle 中做了什么,因为我从未接触过 oracle,但我不知道它是否对你有帮助,但我认为你想这样加入:
SELECT d.department_name, e.salary, e.commission_pct.
FROM departments d
INNER JOIN employees e
ON (e.department_id = d.department_id);
我给你这个 link 有关关节的更多信息: https://sql.sh/cours/jointures 并根据 sql.sh:
There are several methods to associate 2 tables together. Here is the list of the different techniques that are used:
- INNER JOIN: internal join to return the records when the condition is true in both tables. This is one of the most common
joins.- CROSS JOIN: cross join to make the Cartesian product of 2 tables. In other words, allows to join each row of a table with each row of a second table. Attention, the number of results is generally very high.
- LEFT JOIN (or LEFT OUTER JOIN): external join to return all the records of the left table (LEFT = left) even if the condition is not
checked in the other table.- RIGHT JOIN (or RIGHT OUTER JOIN): External join to return all records in the right-hand table (RIGHT = right) even if the condition is not checked in the other table.
- FULL JOIN (or FULL OUTER JOIN) : external join to return the results when the condition is true in at least one of the 2 tables.
- SELF JOIN : allows to join a table with itself as if it were another table.
- NATURAL JOIN : natural join between 2 tables if there is at least one column with the same name between the 2 SQL tables.
- UNION JOIN: joint of union.
如果您有任何问题,我可以回答。