常用的不熟的sql语句
1.select * from dbo.Consum_AccountPaymentLog Where CHARINDEX(',1,',','+RelatedUserIDs+',')>0
charindex 在一个表达式中搜索另一个表达式并返回其起始位置(如果找到)。
之所以‘1’的两边加上‘,’号是为了防止‘11’,‘111’这样的数据扰乱搜索结果
2.select top 5 ProjectID from Work_WorkLog WHERE UserID=3279 GROUP BY ProjectID HAVING COUNT(ProjectID)>0 ORDER BY COUNT(ProjectID) DESC
SELECT TOP 5 ProjectID ,ProjectName FROM Work_WorkLog WHERE UserID = #userId# AND IsDeleted = 0 AND WorkDate >= GETDATE() - 15 GROUP BY ProjectID ,
ProjectName
ORDER BY COUNT(*) DESC
根据一个列的数量多少来进行排序,先对列进行分组,然后判断是否含有该字段,然后根据字段排序,这里要注意的是红色部分要一致
3.select distinct(ProjectName),ProjectID from Work_WorkLog where UserID=3279 and IsDeleted=0 and ProjectID in(select top 5 ProjectID from Work_WorkLog where UserID=3279 group by ProjectID ORDER BY COUNT(ProjectID) DESC)
可以筛选掉重复的数据
4.将字段为空的转化为拼音
Update Sys_Department Set PinYin=dbo.fun_getPY(Name) Where PinYin='' 其中dbo.fun_getPY(Name)为将中文首字母转化为拼音的方法
5.替换
update tra_CruiseItinerary set CruiseMap=REPLACE(CruiseMap,'upload','/upload')
6.对text类型进行替换
update tra_CruiseItinerary set TravelDetail=REPLACE(CAST(TravelDetail as nvarchar(4000)),'<br>','')
6.将英文小写转大写
update Sys_Department set PinYin=UPPER(PinYin)
7.根据某个字段重复的次数排序
select FromCity,COUNT(FromCity) as f from tra_TravelLine group by FromCity order by f desc
8.创建视图
iF EXISTS (SELECT * FROM sysobjects WHERE name = 'tra_AllTravelLine')
DROP VIEW tra_AllTravelLine
GO
CREATE VIEW tra_AllTravelLine
AS
SELECT NEWID() AS ID, Category = 0, Link = m.Link, Picture = m.TravelPic, Name = m.TravelName, Price = m.TravelPrice,SupplierID=m.SupplierID,Supplier = m.SupplierName, FromDate = m.FromDate, City = m.ToCity,
TravelDays = m.TravelDays, TravelNumber = m.TravelNumber, WebType = m.WebType, MobileLink = m.MobileLink,CreateDate=m.CreateDate,FromCity=m.FromCity,NotIncludeCity=m.NotIncludeCity
FROM tra_TravelLine m
UNION ALL
SELECT NEWID() AS ID, Category = 1, Link = n.Link, Picture = n.TravelPic, Name = n.TravelName, Price = n.TravelPrice,SupplierID=n.SupplierID,Supplier = n.SupplierName, FromDate = n.FromDate, City = n.ToCity,
TravelDays = n.TravelDays, TravelNumber = n.TravelNumber, WebType = n.WebType, MobileLink = n.MobileLink,CreateDate=n.CreateDate,FromCity=n.FromCity,NotIncludeCity=n.NotIncludeCity
FROM tra_SelfLine n
GO
常用的不熟的sql语句的更多相关文章
- 50个常用的笔试、面试sql语句
50个常用的笔试.面试sql语句 2009-12-17 15:05 Student(S#,Sname,Sage,Ssex) 学生表Course(C#,Cname,T#) 课程表SC(S#,C#,s ...
- mysql详解常用命令操作,利用SQL语句创建数据表—增删改查
关系型数据库的核心内容是 关系 即 二维表 MYSQL的启动和连接show variables; [所有的变量] 1服务端启动 查看服务状态 sudo /etc/init.d/mysql status ...
- 常用的一些性能查询sql语句
转至:https://blog.csdn.net/bosschen/article/details/84829912 --查看表锁 select * from sys.v_$sqlarea where ...
- 数据分析常用的python工具和SQL语句
select symbol, "price.*" from stocks :使用正则表达式来指定列查询 select count(*), avg(salary) from empl ...
- 常用的获取时间差的sql语句
"select count(*) from [注册] where datediff(day,time,getdate())<1";//获取当天注册人员数 sql=" ...
- 常用判断重复记录的SQL语句
1.查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断select * from people where peopleId in (select peopleId fro ...
- 剑指Offer——常用SQL语句、存储过程和函数
剑指Offer--常用SQL语句.存储过程和函数 常用SQL语句 1.在MySQL数据库建立多对多的数据表关系 2.授权.取消授权 grant.revoke grant select, insert, ...
- 程序员实用的 MySQL sql 语句
这儿只讲究实用, 程序员编程时常用到的 MySQL的 sql语句(不包括基本的 select, update, delete 等语句). 1. 添加一个用户build,并赋予所有权限的命令 gran ...
- Mybatis高级:Mybatis注解开发单表操作,Mybatis注解开发多表操作,构建sql语句,综合案例学生管理系统使用接口注解方式优化
知识点梳理 课堂讲义 一.Mybatis注解开发单表操作 *** 1.1 MyBatis的常用注解 之前我们在Mapper映射文件中编写的sql语句已经各种配置,其实是比较麻烦的 而这几年来注解开发越 ...
随机推荐
- Inversion Sequence(csu 1555)
Description For sequence i1, i2, i3, … , iN, we set aj to be the number of members in the sequence w ...
- The Parallel Challenge Ballgame[HDU1101]
The Parallel Challenge Ballgame Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ( ...
- Redis Java API
package cn.ac.iscas.pebble.dc.redispool; import java.io.File; import java.io.FileOutputStream; impor ...
- Codeforce - Street Lamps
Bahosain is walking in a street of N blocks. Each block is either empty or has one lamp. If there is ...
- BZOJ4027: [HEOI2015]兔子与樱花 贪心
觉得是贪心,但是一开始不太肯定...然后就A了 一个点对它的父亲的贡献就是自己的权值加儿子的个数 #include<bits/stdc++.h> using namespace std; ...
- [IBM DB2] db2 terminate 和 db2 connect reset 有什么区别?
[IBM DB2] db2 terminate 和 db2 connect reset 有什么区别? 总结:如果是退出编辑器 quit :如果是断开数据库连接释放资源 connect reset : ...
- DropDownList 选中change
<script language="javascript" type="text/javascript">$(function(){ $(&q ...
- HighchartsJS创建环形带标识的图表实例
HighchartsJS 是一款功能强大.开源.美观.图表丰富.兼容绝大多数浏览器的纯js图表库,目前最新版本库是Highcharts 4.1.9.另外,HighchartsJS还提供很多的插件和第三 ...
- [CareerCup] 18.6 Smallest One Million Numbers 最小的一百万个数字
18.6 Describe an algorithm to find the smallest one million numbers in one billion numbers. Assume t ...
- [zt]OpenCV如何获取视频当前的一帧图像
(OpenCV读取视频.OpenCV提取视频每一帧.每一帧图片合成新的AVI视频)CvCapture 是视频获取结构 被用来作为视频获取函数的一个参数 比如 CvCapture* cap; IplIm ...