SQL知识积累

一.如何插入一个单引号,用insert into t_user values ('''',3);

二.消息表Message:MessageID  
                         SenderID  发送者ID(对应用户表userID)  
                         ReceiverID 接收者ID(对应用户表userID)
                         MessageTime 发送时间
                        Title 消息标题
                        Body 内容

用户表UserAccount:

UserID 

UserAccount

UserName

要查询某个人相关的消息(发送者或接收者为同一个人):
MessageId,发送者姓名,接收者姓名,消息标题,发送时间

select  m.messageid,

          s.userid as 发送者ID,

          s.username as 发送者姓名,

          r.userid as 接收者ID,

          r.username as 接收者姓名,

          m.title 
from t_message m  join t_user s on m.senderid=s.userid  
                            join t_user r on m.receiveid=r.userid

三.在一个时间段内查询用

                  {and m.MessageTime >= #StartTime#}
                  {and m.MessageTime < DATEADD(DAY,1,#EndTime#)} 

原文地址:https://www.cnblogs.com/ycdx2001/p/1526362.html