通过子查询计算查询两列的差
convert使用按中文排序
locate类似于like
round保留2位小数
using指定字符集using指定utf8时防止乱码
select temp. deposit,temp.prepayment,(temp.prepayment-temp. deposit)availableMoney from(select round(ifnull(deposit,0),2)deposit,round(ifnull(prepayment,0),2)prepayment from encounter where 1=1 and (locate('哈',customer_name)>0 or locate('哈',room_no) or locate('哈',bed_no)) order by convert(customer_name using gbk) asc)temp
本文深入探讨了SQL查询的高级技巧,包括子查询计算列差、使用convert按中文排序、locate函数精确查找、round函数保留小数位数以及指定字符集避免乱码。通过具体案例,展示了如何在复杂条件下优化查询效率。
4765

被折叠的 条评论
为什么被折叠?



