15???????SQL Server?????
???????????? ???????[ 2015/8/28 11:27:01 ] ?????????????
???????????EF?????дsql???洢??????????д???????????棬???????????????ο????о?????????????????????????????????
????1??case…end ??????????
????case?????????????c#?е?switch case
???????case?????????????????when?????????????????????
????-----------------case--end---????---------------------
????select name ?? --?????
????case level --case???????
????when 1 then '???'
????when 2 then '???'
????when 3 then'????'
????end as'???'
????from [user]
????2??case…end ????Χ??
????case ?????????????c#?е?if…else if…else….
???????case????????
????------------------case---end--------------------------------
????select studentId??
????case
????when english between 80 and 90 then '??'
????when english between 60 and 79 then '??'
????else '??'
????end
????from Score
????------------------case---end--------------------------------
????select studentId??
????case
????when english >=80 then '??'
????when english >=60 then '??'
????else '??'
????end
????from Score
????-----------------------------------------------------
????select *??
????case
????when english>=60 and math >=60 then '????'
????else '??????'
????end
????from Score
????3??if…eles
????IF(????????)
????BEGIN --????C#???{
???????1
????……
????END --????C#???}
????ELSE
????BEGIN
???????1
????……
????END
????--??????????????????????????????????????????????????????????????????????????
????declare @avg int --???????
????select @avg= AVG(english) from Score --????????
????select '??????'+CONVERT(varchar??@avg) --??????????
????if @avg<60
????begin
????select '?????'
????select top 3 * from Score order by english desc
????end
????else
????begin
????select '??????'
????select top 3 * from Score order by english
????end
????4??while???
????WHILE(????????)
????BEGIN --????C#???{
???????
????……
????BREAK
????END --????C#???}
????--???????????????????(???????????)???????????????
????select * from Score
????declare @conut int??@failcount int??@i int=0 --???????
????select @conut =COUNT(*) from Score --?????????
????select @failcount =COUNT(*) from Score where english<100 --???δ?????????
????while (@failcount>@conut/2)
????begin
????update Score set english=english+1
????select @failcount=COUNT(*) from Score where english<100
????set @i=@i+1
????end
????select @i
????update Score set english=100 where english >100
????5??????
??????????????????Ч????????????????????????????????????????????????????????????????????Insert??Update??Delete???????????????????????(Where)??????????
????1??????????????????е?????ж??????????????????
????2????????????????????????洢????????????????
????--????????????
????CREATE NONCLUSTERED INDEX [IX_Student_sNo] ON student
????(
????[sNo] ASC
????)
????6??????
????????????????????????????????SQL?????????????????????????????????????????????????????п????????????????????????????????檔
????select * from (select * from student where sAge<30) as t --??????????????б???
????where t.sSex ='??' --??????е?????
??????????λС????CONVERT(numeric(10??2)?? AVG(english))
??????з????????????С????????????????????????????
????select '??????'?? (select AVG(english) from Score) --?????????
????select '????'?? (select sName from student) --???????‘????’?????У?????????????ж???
????select * from student where sClassId in(select cid from Class where cName IN('??????'??'??????')) --?????ж??????in
????7?????
????--???1
????select top 3 * from student
????where [sId] not in (select top (3*(4-1)) [sid] from student)--4??????
????select *?? row_number() over(order by [sage] desc ) from student-- row_number() over (order by..)????к?
????--???2
????select * from
????(select *?? row_number() over(order by [sid] desc ) as num from student)as t
????where num between (Y-1)*T+1 and Y*T
????order by [sid] desc
????--???3
????select * from
????(select ROW_NUMBER() over( order by [UnitPrice] asc) as num??* from [Books] where [publisherid]=1 )as t
????where t.num between 1 and 20 --?????????????????????
????8??????
????select sName??sAge??
????case
????when english <60 then '??????'
????when english IS null then '???'
????else CONVERT(nvarchar?? english)
????end as'?????'
????from student as s
????left join Score as c on s.sid =c.sid
?????????? inner join...on...
???????????on??????????????
??????????
??????????
????left join...on...
????????????е?????????
?????????on??????????????????
??????????
????right join...on...
????????????е?????????
?????????on??????????????????
?????????
????full join ...on...
??????*??????????
????cross join ???on
???????????????к?????????н???????
???????????????????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11