select count(1) from tbl main where main.del =1 and (select count(1) from tbl_sub sub where sub._status != 5 and sub.y_status=7 and sub.ment='ONLINE_PAY' and sub._main_no = main._main_no)>0 and main.member_no = #{loginId} order by main.create_time desc
如上,sub._main_no=main._main_no java
main._main_no这个实际已是一个常量了。如同 sql
for(int i = 0; i < 10; i++) for(int j = i; j < 10; j++)j=i时,i已经能够当作常量了。
相似理解的sql以下: code
,main._status as status ,(case main._status when 0 then '-----' when 1 then '*****' when 2 then '&&&&&' else '其余' end) as status_desc
main._status这儿也能够当作常量来理解了。 xml
sql查询的时候能够如是理解:一行一行查询,写where里面的条件的时候你理解面对你的只是当前某行。记住,是“当前某行”。 class