SELECT * from physician WHERE physician_id NOT EXISTS(SELECT physician_id from user_physician);正确写法
时间: 2023-06-23 09:08:36 浏览: 43
这个 SQL 语句的作用是查询 physician 表中存在但是在 user_physician 表中不存在的医生。
语法上看,这个 SQL 语句是正确的。但是需要根据具体的数据库表结构和数据情况来判断是否能够正确执行。
如果 physician 表中的 physician_id 是主键,并且 user_physician 表中的 physician_id 是外键,那么这个 SQL 语句可以正确执行,并返回 physician 表中所有在 user_physician 表中不存在的医生记录。
但是如果 physician_id 不是主键,或者 user_physician 表中的 physician_id 不是外键,那么这个 SQL 语句可能会返回错误的结果。因此在实际应用中需要根据具体情况来确定 SQL 语句的正确性。
相关问题
请根据以下条件编写sql查询语句:根据sys_tenant表中abbreviation字段和nmp_user表中name字段、phone字段在nmp_user_practicing_physician表中找到user_id
以下是根据给定条件编写的SQL查询语句:
```sql
SELECT nmp_user_practicing_physician.user_id
FROM sys_tenant
JOIN nmp_user ON sys_tenant.abbreviation = nmp_user.name
JOIN nmp_user_practicing_physician ON nmp_user.phone = nmp_user_practicing_physician.phone;
```
请注意,这只是一个示例查询语句,具体的表名和字段名可能需要根据你的数据库结构进行调整。
org.springframework.data.domain.Page<PhysicianSerVo> 这种写法有问题吗
这种写法没有问题,它是Spring Data提供的分页查询的一种方式。其中,PhysicianSerVo是你要查询的实体类,Page是Spring Data提供的分页查询结果的封装类。它可以方便地进行分页查询操作,包括设置每页显示的数量、当前页码等信息。在使用时,你需要在DAO层定义一个方法,返回类型为Page<PhysicianSerVo>,并传入Pageable参数,这样就可以进行分页查询了。例如:
```java
@Repository
public interface PhysicianRepository extends JpaRepository<Physician, Long> {
Page<PhysicianSerVo> findBySpecialty(String specialty, Pageable pageable);
}
```
这个方法会根据专业名称进行分页查询,并返回Page<PhysicianSerVo>类型的结果。你可以调用该方法,传入Pageable参数,获取指定页码的查询结果。