常用SQL

查询类:

select* from SignPointActivity 

select* from SignPointActivity where Title='一个签到'

select* from SignRecords  where Memberlogin='13800138000'  and ActivityID=329

select * from MemberSignatureCard where Memberlogin='13800138000' and OpenID='os9ZrtwmqazVNkTuIg2wvQCmsr3c' and ActivityID='319' order by AddTime
update MemberSignatureCard set IsUse=0 where ID in('28','29','30','31','32','33','34','35')

select SalesRecords.orderID,Orders.openid from SalesRecords as SalesRecords left join Orders as Orders on SalesRecords.orderID=Orders.orderID where
SalesRecords.productname='特殊测试虚拟' and SalesRecords.PublishedTime>'2018-01-18 14:46:00' and SalesRecords.PublishedTime<'2018-01-18 15:46:00'

SELECT ((Commentcount*0.4+Viewcount*0.3+Likecount*0.3)/ power((DATEDIFF(d, Createtime, GETDATE())+2.000000),1.8)) as hot ,Title,Commentcount,Viewcount,Likecount FROM [dbo].[Article]  where Status in ('1','2') and MemberLogin='1008601' ORDER BY hot DESC;

添加类:

insert into SignRecords (Openid,NickName,YYYYMMDD,hbSend,Memberlogin,ActivityID,TotalNumber)
values ('os9ZrtwmqazVNkTuIg2wvQCmsr3c','Jerry','2017-04-30',0,13800138000,302,1);

DECLARE @i int
DECLARE @opid nvarchar(200)
Set @i = 1
SET @opid='123123123'

WHILE @i < 5000
BEGIN
Set @i =@i +1
set @opid = @opid+@i
insert into Fact_Statistic_SignatureCard(RQ,Memberlogin,ActivityID,Openid,Num,UseNum,IsDelete,InvitationNum,AddTime) values('2017-04-27','13800138000',237,@opid,2,3,0,0,'2017-04-27 19:00:44.407')
END

删除类:

delete from SignPointActivity where ID = '412' 

delete from SignRecords where ID in(22029,
22055,
22056,
22057,
22059,
22062)

更新类:

update SignPointActivity set EndTime='2017-11-30 11:43:00' where ID=407

原文地址:https://www.cnblogs.com/testwjr/p/8664472.html