[英]inner join using mongo query (pymongo)
我是 SQL 查詢的新手,第一次使用 Pymongo 使用 MongoDB。
我在 MongoDB 中有兩個 collections。
DEPARTMENT
dept_id dept_name status location
------------------------------------------
123 sales active New York
248 IT inactive Vermont
845 HR active LA
EMPLOYEE
dept_id emp_name emp_salary emp_status emp_id
----------------------------------------------------
123 John 25000 active xyz
845 Mary 90000 active abc
248 Kevin 50000 inactive qrs
query 1
select * from DEPARTMENT where dept_id=123 and status='active'
query 2
select emp_name, emp_id from EMPLOYEE where dept_id =123 and status = 'active'
我想內部加入這 2 個查詢並返回所有匹配的記錄,並從 DEPARTMENT 表和 EMPLOYEE 表中的 emp_name、emp_id 中提供所有詳細信息。
我將如何使用 pymongo 和 sql 查詢來實現它。
任何幫助將不勝感激!
提前致謝!
嘗試這個:
SELECT
EMPLOYEE.emp_name,
EMPLOYEE.emp_id,
DEPARTMENT.*
FROM
EMPLOYEE LEFT JOIN DEPARTMENT ON EMPLOYEE.dept_id = DEPARTMENT.dept_id
WHERE
EMPLOYEE.dept_id = 123
AND EMPLOYEE.status = 'active'
AND DEPARTMENT.status = 'active'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.