当前位置:编程学习 > wap >>

一个SQL group by 的用法

SQL group by 用法
有这样一个表   
id  发送者ID   接受者ID   内容
1    A_ID           B_ID        XXXX
2    A_ID            B_ID       YYYY
3     A_ID          B_ID         ZZZZ
4    C_ID          A_ID          OOO
5     B_ID           A_ID          PPPPP
6      B_ID        A_ID            QQ
7      A_ID          D_ID           MMMM
8     D_ID          A_ID             NNNNN
去除重复,将与A_ID有过关系的 B_ID , C_ID ,D_ID的ID查出来
--------------------编程问答-------------------- 如果用
select dstinct 发送者ID from table1 where 接收者ID = 'A_ID'
union
select distinct 接收者ID from table1 where 发送者ID ='A_ID'

select distinct case 发送者ID ='A_ID' then 接收者ID else 发送者ID end from table1 where
接收者ID ='A_ID'  or 发送者ID = 'A_ID'  可以不用group by 的
但是在下面写了while (cursor.moveToNext()) {
   Message message= new Message ();
    message.id = cursor.getString(cursor
     .getColumnIndex("id"));
     message.senderId = cursor.getString(cursor
     .getColumnIndex("senderId"));
   message.recipientId = cursor.getString(cursor
     .getColumnIndex("receId"));
    list.add(message);
  }

报错 ,需求是要得到message对象及里面的参数数据,只用select distinct 是不行的,该怎么改呢?需要用select * from ?
--------------------编程问答-------------------- 我用SQL,想从表message_table里查到所有与 "发送者 A "有过聊天记录的用户,表是保存消息message的表,字段有发送者senderID和接收者receID,发送的内容,希望查询到message里去掉重复的用户ID,  "发送者 A" 可以作为发送者也可以作为接收者, --------------------编程问答-------------------- 哪位朋友会,帮忙一下吧
补充:移动开发 ,  Android
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,