加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

sqlite3 联表查询 代码

发布时间:2020-12-12 19:52:30 所属栏目:百科 来源:网络整理
导读:select USER.USERNAME,USER.USERNAMEP,USER.PHOTOURL,USER.ADMIN,USEREX.RELATION,USEREX.SUBRELATION,USEREX.LASTTIME,_MESSAGE.CONTENT,_MESSAGE.SENDTYPE,_MESSAGE.DIRECTION from USER,USEREX left join ( select CONTENT,max(TIMETAG) as MAXTIMETAG,
  1. select USER.USERNAME,USER.USERNAMEP,USER.PHOTOURL,USER.ADMIN,USEREX.RELATION,USEREX.SUBRELATION,USEREX.LASTTIME,_MESSAGE.CONTENT,_MESSAGE.SENDTYPE,_MESSAGE.DIRECTION from USER,USEREX left join (select CONTENT,max(TIMETAG) as MAXTIMETAG,DIRECTION,SENDTYPE from MESSAGE where MYID = ? and USERID = ? and GROUPID = 0)_MESSAGE where USER.USERID = ? and USEREX.USERID = USER.USERID and USEREX.MYID = ? and USEREX.LASTTIME > 0;
  2. (select xxx from xxx left join(select xxx from xxx where xxx) xxx where xxx);

  1. select MESSAGE.USERID,MESSAGE.DIRECTION,MESSAGE.CONTENT,MESSAGE.TIMETAG,MESSAGE.MYID,MESSAGE.SENDTYPE,MESSAGE.TIMESPAN,MESSAGE.UNREADFLAG,USER.USERNAME from MESSAGE left join USER on MESSAGE.USERID = USER.USERID where MESSAGE.USERID >= 0 and MESSAGE.MYID = ? and MESSAGE.GROUPID = ? order by MESSAGE.TIMETAG desc limit ?;
  2. (select xxx from xxx left join xxx on xxx where xxx);

select USER.USERID,USER.USERNAME,_MESSAGE.MAXTIMETAG,_MESSAGE.DIRECTION,MESSAGECOUNT.COUNT,USER.SEX from USER,USEREX left join (select USERID,max(TIMETAG) as MAXTIMETAG,CONTENT,SENDTYPE from MESSAGE where MYID = ? and GROUPID = 0 group by USERID) _MESSAGE on USEREX.USERID = _MESSAGE.USERID left join MESSAGECOUNT on MESSAGECOUNT.ID = USEREX.USERID and MESSAGECOUNT.TYPE = 0 and MESSAGECOUNT.MYID = ? where USEREX.LASTTIME > 0 and USEREX.MYID = ? and USER.USERID = USEREX.USERID;

(select xxx from xxx left join (select xxx as xxx from xxx where xxx group by xxx) on xxx left join xxx on xxx where xxx)



select GROUPS.GROUPID,GROUPS.GROUPNAME,GROUPS.GROUPNAMEP,GROUPS.PICTUREURL,GROUPEX.LASTTIME,MESSAGECOUNT.COUNT from GROUPS,GROUPEX

left join (select MESSAGE.GROUPID,_MSGTMP.MAXTIMETAG,MESSAGE.USERID,MESSAGE.SENDTYPE from MESSAGE,(select max(TIMETAG) as MAXTIMETAG,GROUPID from MESSAGE where MYID = ? and USERID >= 0 and GROUPID > 0 group by GROUPID) _MSGTMP where MESSAGE.GROUPID = _MSGTMP.GROUPID and MESSAGE.TIMETAG = _MSGTMP.MAXTIMETAG and MESSAGE.MYID = ?) _MESSAGE on GROUPEX.GROUPID = _MESSAGE.GROUPID

left join USER on USER.USERID = _MESSAGE.USERID

left join MESSAGECOUNT on MESSAGECOUNT.MYID = ? and MESSAGECOUNT.ID = GROUPEX.GROUPID and MESSAGECOUNT.TYPE = 1

where GROUPEX.MYID = ? and GROUPEX.GROUPID > 0 and GROUPEX.LASTTIME > 0 and GROUPS.GROUPID = GROUPEX.GROUPID;


(select xxx from xxx left join (select xxx from (select xxx from xxx where xxx group by xx) where xxx )on xxx left join xxx on xxx let join xxx on xxx where xxx)

备注:“” ,代表行末换行的意思

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读