[SQL]SELECT stuName from student WHERE tuNo=(SELECT stuNO from result where stuResuit>60); [Err] 1242 - Subquery returns more than 1 row
时间: 2024-05-10 11:17:27 浏览: 8
这个错误是因为你的子查询返回了多行结果,而在这个查询中只能返回一行结果。你可以考虑使用IN关键字来代替等于号进行查询,例如:
```
SELECT stuName FROM student WHERE stuNo IN (SELECT stuNO FROM result WHERE stuResuit > 60);
```
这样就可以查询出所有stuNo对应的stuName了。
相关问题
private static final String SQL_INSERT = "insert into stu2005 VALUES(?,?,?,?)"; private static final String SQL_DELECT = "DELETE from stu2005 WHERE stuno=?"; private static final String SQL_UPDATE = "UPDATE stu2005 SET stuname=? WHERE stuno=?"; private static final String SQL_SELECT = "SELECT * FROM stu2005 WHERE stuname=?"; @Override
这段代码看起来是一个实现了数据库增删改查功能的类,具体分别为:
1. 插入数据,即往stu2005表中插入一条记录。SQL_INSERT语句中的问号是占位符,表示待插入的数据,具体的值需要在执行插入操作时传入。
```java
private static final String SQL_INSERT = "insert into stu2005 VALUES(?,?,?,?)";
```
2. 删除数据,即从stu2005表中删除一条记录,需要指定stuno作为删除条件。SQL_DELECT语句中的问号是占位符,表示待删除的记录的stuno,具体的值需要在执行删除操作时传入。
```java
private static final String SQL_DELECT = "DELETE from stu2005 WHERE stuno=?";
```
3. 更新数据,即更新stu2005表中的一条记录,需要指定stuno作为更新条件。SQL_UPDATE语句中的问号是占位符,表示待更新的记录的stuname和stuno,具体的值需要在执行更新操作时传入。
```java
private static final String SQL_UPDATE = "UPDATE stu2005 SET stuname=? WHERE stuno=?";
```
4. 查询数据,即从stu2005表中查询符合stuname条件的记录。SQL_SELECT语句中的问号是占位符,表示查询条件,具体的值需要在执行查询操作时传入。
```java
private static final String SQL_SELECT = "SELECT * FROM stu2005 WHERE stuname=?";
```
需要注意的是,这些SQL语句中的问号是为了防止SQL注入攻击而设置的占位符,具体的值需要在执行操作时传入。另外,这段代码中的@Override注解表示该方法是覆盖了父类或接口的方法,可以帮助编译器检查是否正确地实现了该方法。
前端传来的搜索条件 1. pageNum: 1 2. pageSize: 20 3. schoolId: 12 4. clockTime_begin: 2023-08-02 5. clockTime_end: 2023-08-03 ``` <select id="selectAttStudentRecordList" parameterType="AttStudentRecord" resultMap="AttStudentRecordResult"> <include refid="selectAttStudentRecordVo"/> <where> <if test="schoolId != null "> and school_id = #{schoolId}</if> <if test="parentId != null "> and parent_id = #{parentId}</if> <if test="studentId != null "> and student_id = #{studentId}</if> <if test="stuName != null and stuName != ''"> and stu_name like concat('%', #{stuName}, '%')</if> <if test="stuNo != null and stuNo != ''"> and stu_no = #{stuNo}</if> <if test="cardNo != null and cardNo != ''"> and card_no = #{cardNo}</if> <if test="clockType != null "> and clock_type = #{clockType}</if> <if test="imgUrl != null and imgUrl != ''"> and img_url = #{imgUrl}</if> <if test="clock_time != null" > and clock_time =#{clockTime}</if> <if test="channelName != null and channelName != ''"> and channel_name like concat('%', #{channelName}, '%')</if> <if test="deviceId != null "> and device_id = #{deviceId}</if> <if test="tenantId != null "> and tenant_id = #{tenantId}</if> and del_flag = 0 </where> </select> 我在xml文件中的where要怎么写
你可以根据前端传来的搜索条件,在XML文件的`<where>`标签中编写相应的条件语句。以下是根据你提供的搜索条件示例的XML代码示例:
```xml
<select id="selectAttStudentRecordList" parameterType="AttStudentRecord" resultMap="AttStudentRecordResult">
<include refid="selectAttStudentRecordVo" />
<where>
<if test="schoolId != null ">and school_id = #{schoolId}</if>
<if test="clockTime_begin != null ">and clock_time >= #{clockTime_begin}</if>
<if test="clockTime_end != null ">and clock_time <= #{clockTime_end}</if>
and del_flag = 0
</where>
</select>
```
以上示例中,根据前端传来的搜索条件,我仅添加了`schoolId`和`clockTime`的判断条件。你可以根据需要添加其他条件,如`pageNum`、`pageSize`等。
请注意,示例中使用了`>=`和`<=`来表示大于等于和小于等于的比较操作符,这是因为XML文件中需要使用实体编码来表示特殊字符。
希望这能帮到你!如果有任何进一步的问题,请随时问我。