1.top 100  选取表中前100条
改为 limit #{limit},limit 为变量
2.获取当前日期getdate()
改为now()
3.id=#{id,jdbcType=BIGINT}
改为id=#{id},不需要指定数据类型
4.sqlserver查询需要nolock
而mysql不需要
5.字符串拼接
sqlserver:select * from A where contract_no like '%'+'DSP'+'%' order by id desc
mysql:select * from A where contract_no like concat('%','DSP','%') order by id desc
单向拼接用
concat('_%',#{waybillNo})
concat('%',#{waybillNo},'%')
6.分页查询时
mysql不支持ROW_NUMBER() OVER,也不支持with cte1 as()语法
sqlserver:
 <select >
                AND parta_no = #{parta_no, jdbcType=VARCHAR}
            </if>
        </where>
        group by contract_info_id )
        order by t1.id desc
        limit #{startRow},#{pageSize}
    </select>
7.分页查询时注意 limit #{startRow},#{pageSize}取得startRow必须从0开始,可能在controller层要改变下起始页码,取决于引用的分页法,也要注意查询总数为0时,0-1=-1,起始页面不可以为-1,要区分对待。
8.sqlserver isnull(t1.parta_num,0)转化为mysql ifnull(t1.parta_num,0)
MySQL IFNULL函数是MySQL控制流函数之一,它接受两个参数,如果不是NULL,则返回第一个参数。 否则,IFNULL函数返回第二个参数。

两个参数可以是文字值或表达式。

以下说明了IFNULL函数的语法:

IFNULL(expression_1,expression_2);
SQL

如果expression_1不为NULL,则IFNULL函数返回expression_1; 否则返回expression_2的结果。

IFNULL函数根据使用的上下文返回字符串或数字。

如果要返回基于TRUE或FALSE条件的值,而不是NULL,则应使用IF函数。
9.int 类型 sqlserver默认为0,而mysql默认为null。

10.多表关联update区别

sqlserver:

update a set a.invoice_apply_amount=a.invoice_apply_amount+b.invoicing_amount,a.uninvoiced_balance =a.uninvoiced_balance+b.invoicing_amount,a.invoiced_amount=a.invoiced_amount-b.invoicing_amount from A  a,B b where a.contract_no =b.contract_no and b.apply_no='11111'

mysql:

UPDATE A a,B b
SET a.invoice_apply_amount=a.invoice_apply_amount+b.invoicing_amount,a.uninvoiced_balance =a.uninvoiced_balance+b.invoicing_amount,a.invoiced_amount=a.invoiced_amount-b.invoicing_amount
WHERE  a.contract_no =b.contract_no and b.apply_no='11111'

相关文章: