UPDATE T_ORG_BaseUnit A INNER JOIN T_BD_Industry B on A.CFBUSINESSUNIT=B.FNAME_L2 SET A.T_ORG_BaseUnit = B.FID where A.CFBUSINESSUNIT is not null
时间: 2024-04-10 17:29:12 浏览: 248
这是一个更新语句,它使用了INNER JOIN来连接表T_ORG_BaseUnit和T_BD_Industry。连接条件是T_ORG_BaseUnit表的CFBUSINESSUNIT列与T_BD_Industry表的FNAME_L2列相等。这个语句将T_ORG_BaseUnit表的T_ORG_BaseUnit列更新为T_BD_Industry表的FID列的值。更新的条件是CFBUSINESSUNIT列不为空。
相关问题
MERGE INTO t_org_baseunit a USING t_org_baseunit_temp_20230607 b ON (a.fnumber = b.fnumber) WHEN MATCHED THEN UPDATE SET a.cfehrorgnumber = b.cfehrorgnumber, a.flastupdatetime = SYSDATE
这是一条 SQL 语句,它的作用是将 t_org_baseunit_temp_20230607 表中的数据更新到 t_org_baseunit 表中。具体操作是将两个表中 fnumber 字段相同的记录进行匹配,然后将 t_org_baseunit 表中匹配到的记录更新,设置 cfehrorgnumber 和 flastupdatetime 字段的值为 t_org_baseunit_temp_20230607 表中对应记录的值。其中,UPDATE SET 语句用于更新字段的值,SYSDATE 函数用于获取当前系统时间。
SELECT m.FNUMBER as id, m.FNAME_L2 as name, d.FNAME_L2 as unit, m.FMODEL as model FROM PONYPUNI3.T_BD_MATERIALPURCHASING mp INNER JOIN PONYPUNI3.T_BD_MATERIAL m ON m.FID = mp.FMATERIALID LEFT OUTER JOIN PONYPUNI3.T_BD_MeasureUnit d on m.fbaseunit=d.fid WHERE mp.FSTATUS = 1 AND m.FSTATUS = 1 AND mp.FORGUNIT=:org AND ( m.FNUMBER LIKE :keyword OR m.FNAME_L2 LIKE :keyword OR m.FMODEL LIKE :keyword ) 怎么用spring jpa @JoinColumn实现
要使用Spring JPA的@JoinColumn注解实现上述查询,你需要进行以下步骤:
1. 创建一个实体类,映射到数据库中的表PONYPUNI3.T_BD_MATERIALPURCHASING。示例代码如下:
```java
@Entity
@Table(name = "PONYPUNI3.T_BD_MATERIALPURCHASING")
public class MaterialPurchasing {
@Id
@Column(name = "FID")
private Long id;
@OneToOne
@JoinColumn(name = "FMATERIALID")
private Material material;
// 添加其他属性对应数据库字段
// 添加对应的getter和setter方法
}
```
2. 创建一个实体类,映射到数据库中的表PONYPUNI3.T_BD_MATERIAL。示例代码如下:
```java
@Entity
@Table(name = "PONYPUNI3.T_BD_MATERIAL")
public class Material {
@Id
@Column(name = "FID")
private Long id;
@Column(name = "FNUMBER")
private String number;
@Column(name = "FNAME_L2")
private String name;
@Column(name = "FMODEL")
private String model;
@OneToOne(mappedBy = "material")
private MaterialPurchasing materialPurchasing;
@OneToOne
@JoinColumn(name = "FBASEUNIT")
private MeasureUnit baseUnit;
// 添加其他属性对应数据库字段
// 添加对应的getter和setter方法
}
```
3. 创建一个实体类,映射到数据库中的表PONYPUNI3.T_BD_MeasureUnit。示例代码如下:
```java
@Entity
@Table(name = "PONYPUNI3.T_BD_MeasureUnit")
public class MeasureUnit {
@Id
@Column(name = "FID")
private Long id;
@Column(name = "FNAME_L2")
private String name;
// 添加其他属性对应数据库字段
// 添加对应的getter和setter方法
}
```
4. 创建一个Spring Data JPA的Repository接口,用于对数据库表PONYPUNI3.T_BD_MATERIALPURCHASING进行操作。示例代码如下:
```java
@Repository
public interface MaterialPurchasingRepository extends JpaRepository<MaterialPurchasing, Long> {
List<MaterialPurchasing> findByStatusAndOrgUnitAndMaterialInfoContaining(int status, String org, String keyword);
}
```
5. 在你的服务类中注入MaterialPurchasingRepository,并调用findByStatusAndOrgUnitAndMaterialInfoContaining方法进行查询。示例代码如下:
```java
@Service
public class MaterialService {
private final MaterialPurchasingRepository materialPurchasingRepository;
public MaterialService(MaterialPurchasingRepository materialPurchasingRepository) {
this.materialPurchasingRepository = materialPurchasingRepository;
}
public List<MaterialPurchasing> searchMaterialInfo(String org, String keyword) {
int status = 1;
return materialPurchasingRepository.findByStatusAndOrgUnitAndMaterialInfoContaining(status, org, keyword);
}
}
```
请确保在Spring Boot项目中已经正确配置了数据库连接和JPA相关的配置。这样就可以使用Spring JPA的@JoinColumn注解实现上述查询了。
阅读全文