<!-- 计算每两次消费的间隔天数 --> SELECT B.MEN_ID,TIMESTAMPDIFF(DAY,B.PRE_DATE,B.CURR_DATE) AS DAYS FROM ( <!-- 行变列 --> SELECT A.MEN_ID,A.ORDER_DATE AS CURR_DATE,@A.ORDER_DATE AS PRE_DATE,@A.ORDER_DATE:= A.ORDER_DATE FROM TBL_MAS_ORDER_MASTER A,(SELECT @A.ORDER_DATE:=NULL) S ) B WHERE B.PRE_DATE IS NOT NULL