mysql 1.取出数据为null,替换为默认值 2.从选出的数据中再筛选数据

SELECT count(*) FROM 
( 	
				SELECT
			user.*,invite.username as inviteUser,IFNULL(invite.tele ,"")as inviteTele,IFNULL(invite.insert_time ,"")as inviteTime
			FROM
			user left join  (select invite_record.*,user.username,user.tele from invite_record left join user on user.id = invite_record.invite_user_id) as invite on user.id = invite.user_id
	)	AS final
				WHERE
		inviteTele LIKE #{inviteTele}
			AND
		inviteTime LIKE #{inviteDate}
  • 知识点1:

取出数据为null,替换为默认值

语法:

IFNULL(替换字段名,默认值)as 字段名

 

  • 知识点2

从选出的数据中再筛选数据

语法:

select * from(select * from a)as b where ...

将选出来的数据 as为新表名,再进行其它操作

 

 

你可能感兴趣的:(mysql)