SELECT t.id,t.order_number,t.registration_Time,t.inspect_unit,t.inspect_form,t.unit_type,t.unit_ids,t.unit_name, t.problem,t.ask_leave_ids,t.ask_leave_name,t.disposal_situation,t.catalog_id,t.street_name,t.check_street_ids,t.check_street_name,t.receive_Unit,sd.dept_name AS receive_Unit_Name FROM tb_duty_inspect_class t LEFT JOIN tb_sys_dept sd ON sd.ID = t.receive_Unit WHERE t.is_delete='0' 我要根据receive_Unit 查询unit_name
时间: 2024-02-25 17:56:27 浏览: 17
好的,您需要根据 `receive_Unit` 查询 `unit_name`,可以使用以下 SQL 语句:
```
SELECT t.unit_name
FROM tb_duty_inspect_class t
LEFT JOIN tb_sys_dept sd ON sd.ID = t.receive_Unit
WHERE t.is_delete = '0' AND sd.dept_name = 'receive_unit的值';
```
其中 `receive_unit的值` 部分需要替换成您想要查询的 `receive_unit` 的具体值。执行该 SQL 语句后,会返回符合条件的 `unit_name`。
相关问题
SELECT t.id,t.order_number,t.registration_Time,t.inspect_unit,t.inspect_form,t.unit_type,t.unit_ids,t.unit_name, t.problem,t.ask_leave_ids,t.ask_leave_name,t.disposal_situation,t.catalog_id,t.street_name,t.check_street_ids,t.check_street_name,t.receive_Unit,sd.dept_name AS receive_Unit_Name FROM tb_duty_inspect_class t LEFT JOIN tb_sys_dept sd ON sd.ID = t.receive_Unit WHERE t.is_delete='0' 我要根据receive_Unit_Name字段中的值来查询unit_name中的值怎么写
您可以使用子查询的方式来实现这个查询,具体的 SQL 语句如下:
```
SELECT t.id,t.order_number,t.registration_Time,t.inspect_unit,t.inspect_form,t.unit_type,t.unit_ids,t.unit_name,
t.problem,t.ask_leave_ids,t.ask_leave_name,t.disposal_situation,t.catalog_id,t.street_name,t.check_street_ids,t.check_street_name,
t.receive_Unit,sd.dept_name AS receive_Unit_Name
FROM tb_duty_inspect_class t
LEFT JOIN tb_sys_dept sd ON sd.ID = t.receive_Unit
WHERE t.is_delete='0' AND t.unit_name IN (
SELECT unit_name
FROM tb_duty_inspect_class
LEFT JOIN tb_sys_dept ON tb_sys_dept.ID = tb_duty_inspect_class.receive_Unit
WHERE tb_sys_dept.dept_name = 'receive_Unit_Name'
)
```
其中,子查询部分会根据 `receive_Unit_Name` 字段的值查询出符合条件的 `unit_name`,外层查询则会根据这些 `unit_name` 的值来筛选出对应的数据记录。
Se t. un i on ( a, b)
`Set.union(a, b)` 是指将两个 Set 集合对象 `a` 和 `b` 进行合并并返回一个新的 Set 集合,新的集合中包括原先两个集合中的所有不重复元素。在 Ruby 中,Set.union 可以通过 `a.union(b)` 的方式调用。例如:
```
require 'set'
a = Set.new([1, 2, 3])
b = Set.new([2, 3, 4])
c = a.union(b)
puts c.to_a.inspect # 输出 [1, 2, 3, 4]
```
这里,`a` 和 `b` 分别是包含不同元素的两个 Set 集合,通过 `Set#union` 方法进行合并得到新的集合 `c`,最终输出 `c` 中的元素。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)