日期:2014-05-16 浏览次数:21047 次
1.MySQL中实现类似于 SQL Server 中row_number() over(partition by )函数
Select ProjectPlan_ID,Project_ID,ProjectPlan_Name,BeginDate,EndDate,Memo,ProjectPlan_StepIndex from (
select ProjectPlan_ID,Project_ID,ProjectPlan_Name,BeginDate,EndDate,Memo,@rownum:=@rownum+1,if(@pid=tpmpp.Project_ID,@ProjectPlan_StepIndex:=@ProjectPlan_StepIndex+1,@ProjectPlan_StepIndex:=1) as ProjectPlan_StepIndex,
@pid:=tpmpp.Project_ID
from(
select * from T_PM_ProjectPlan order by Project_ID,BeginDate)? tpmpp,(select @rownum:=0,@pid:=null,@ProjectPlan_StepIndex:=0) a ) result
2.Mysql 没有ISNULL(exp1,exp2)而是IFNULL(exp1,exp2)
3.Mysql 获取数据库系统当前时间函数为 NOW()或者 cur_Date()
4. MySQL不支持nchar,nvarchar,ntext类型
5.MySQL的递增语句是AUTO_INCREMENT,而MS SQL是identity(1,1)
6.SQL Server中Image、uniqueidentifier分别对应于MySql的Longblob和varChar类型
7. MS SQL不支持limit语句,只能用top 取代limit 0,N,row_number() over()函数取代limit N,M
8.MySql+ iBATIS模式下,数据库操作文件xml中不支持两个完全独立的更新或删除语句,比如:在SQL Server+iBATIS 模式下可以支持一下写法
<delete id="deleteAll" parameterClass="project">
????? <![CDATA[
????? delete from T_Base_UploadFile where T_Base_UploadFile.yw_id in (select pp.ProjectPlan_ID from T_PM_ProjectPlan as pp
? where pp.project_ID = #project_ID#) and T_Base_UploadFile.ywTable='projectPlan';
? delete t1,t2,t3 from T_PM_Project as t1,T_PM_ProjectPlan as t2,T_PM_Project_User as t3 where t1.Project_ID=#project_ID# and t2.Project_ID=#project_ID# and t3.Project_ID=#project_ID#;?
???? ]]>
</delete>
但在MySQL+iBATIS则需要进行如下修改
<delete id="deleteAll_1" parameterClass="project">
? <![CDATA[
? delete from T_Base_UploadFile where T_Base_UploadFile.yw_id in (select pp.ProjectPlan_ID from T_PM_ProjectPlan as pp
where pp.project_ID = #project_ID#) and T_Base_UploadFile.ywTable='projectPlan';
]]>
</delete>
<delete id="deleteAll_2" parameterClass="project">
<![CDATA[
delete t1,t2,t3 from T_PM_Project as t1,T_PM_ProjectPlan as t2,T_PM_Project_User as t3 where t1.Project_ID=#project_ID# and t2.Project_ID=#project_ID# and t3.Project_ID=#project_ID#;
]]>
</delete>
9. 在MySQL中 ,不能从一个表中删除或更新时,同时又在子查询中从同一个表中选择,比如:
delete from T_Base_CheckProcs where yw_id not in
(select t.yw_id from T_Base_CheckProcs t where t.checkProc_ID=13 and t.PassState='9') and checkProc_ID=13
以上SQL语句可以在SQL Server正常执行,但在MySQL数据库下,却不能执行,会出现如下错误提示:?
ERROR 1093 (HY000): You can't specify target table 'T_Base_CheckProcs ' for update in FROM clause
需要进行如下修改:
delete from T_Base_CheckProcs where yw_id not in
(select temp.yw_id from (select t.yw_id,t.checkProc_ID,t.PassState from T_Base_CheckProcs t )temp where temp.checkProc_ID=13 and temp.PassState='9')
and checkProc_ID=13
10.SQL Server、Oracle、MySQL 分页区别
SQL Server:
SELECT TOP 页大小 *
FROM A
WHERE (ID NOT IN (???
????? SELECT TOP (页大小-1)*页数 id
?????? FROM A ORDER BY id)) ORDER BY ID
Oracle:
SELECT * FROM
(SELECT A.*, ROWNUM RN
FROM (SELECT * FROM TABLE_NAME ORDER BY …) A
WHERE ROWNUM <=页数*页大小)
WHERE RN >= (页数-1)*页大小+1
MySQL:
SELECT * FROM A WHERE …ORDER BY… LIMIT (页数-1)*页大小+1,页数*页大小
?