1.比如学生表
如何显示查询结果的顺序根据放置的顺序查询
<select id="selectNames" resultType="Student">
select * from `student_table` where 1=1
<if test="studentList!= null">
and name in
<foreach item="item" index="index" collection="studentList" open="(" close=")" separator=",">
#{item.name}
</foreach>
order by field (name,
<foreach item="item" index="index" collection="studentList" close=")" separator=",">
#{item.name}
</foreach>
</if>
</select>
日志打印的结果
select * from student_table where 1=1 and name in ( ? , ? ) order by field (name , ? , ? )
2.mysql语句 如何统计一个字段中每个不同数值出现的次数
如果你想统计一个字段中每个不同数值出现的次数,可以使用以下的 MySQL 语句:
SELECT field_name, COUNT(*) as count
FROM your_table
WHERE field_name > 1
GROUP BY field_name
HAVING COUNT(*) > 1
ORDER BY count DESC
在这个查询中:
your_table
是你要查询的表名。field_name
是你要统计的字段名,假设是一个数字字段。
这个查询会返回该字段中每个不同数值以及它们出现的次数,只显示出现次数大于1的记录。