mysql第三天

摘要:
未使用别名(alias)1mysql˃SELECTDATE_FORMAT(t,'%M%e,%Y'),2-˃srcuser,sizeFROMmail;3+----------------------------+---------+---------+4|DATE_FORMAT(t,'%M%e,%Y')|srcuser|size|5+----------------------------+----
未使用别名(alias)
1 mysql>SELECTDATE_FORMAT(t,'%M %e, %Y'),
2 ->srcuser, size FROMmail;
3 +----------------------------+---------+---------+4 |DATE_FORMAT(t,'%M %e, %Y') |srcuser |size |5 +----------------------------+---------+---------+6 |May 11, 2006|barb |58274|7 |May 12, 2006|tricia |194925|8 |May 12, 2006|phil |1048|9 |May 13, 2006|barb |271|10 |May 14, 2006|gene |2291|11 |May 14, 2006|phil |5781|12 |May 14, 2006|barb |98151|13 |May 14, 2006|tricia |2394482|14 |May 15, 2006|gene |3824|15 |May 15, 2006|phil |978|16 |May 15, 2006|gene |998532|17 |May 15, 2006|gene |3856|18 |May 16, 2006|gene |613|19 |May 16, 2006|phil |10294|20 |May 17, 2006|phil |873|21 |May 19, 2006|gene |23992|22 +----------------------------+---------+---------+23 16rows inset(0.00sec)
使用别名
mysql第三天第1张mysql第三天第2张代码
1 mysql>SELECTDATE_FORMAT(t, '%M %e, %Y') AS'Date of message',
2 ->srcuser AS'Message sender', size AS'Number of bytes'FROMmail;
3 +-----------------+----------------+-----------------+4 |Date ofmessage |Message sender |Numberofbytes |5 +-----------------+----------------+-----------------+6 |May 11, 2006|barb |58274|7 |May 12, 2006|tricia |194925|8 |May 12, 2006|phil |1048|9 |May 13, 2006|barb |271|10 |May 14, 2006|gene |2291|11 |May 14, 2006|phil |5781|12 |May 14, 2006|barb |98151|13 |May 14, 2006|tricia |2394482|14 |May 15, 2006|gene |3824|15 |May 15, 2006|phil |978|16 |May 15, 2006|gene |998532|17 |May 15, 2006|gene |3856|18 |May 16, 2006|gene |613|19 |May 16, 2006|phil |10294|20 |May 17, 2006|phil |873|21 |May 19, 2006|gene |23992|22 +-----------------+----------------+-----------------+23 16rows inset(0.00sec)
字符串与表达式的区别

数字靠右边对齐

字符串靠左边对齐

‘1+1+1’ 表示 一个字符串

没加引号的1+1+1 是一个表达式

mysql第三天第3张mysql第三天第4张代码
1 mysql>SELECT'1+1+1'AS'the expression', 1+1+1AS'The result';
2 +----------------+------------+3 |the expression |The result |4 +----------------+------------+5 |1+1+1|3|6 +----------------+------------+7 1row inset(0.00sec)
合并多列组成复合值

CONCAT() 使用

mysql第三天第5张mysql第三天第6张代码
mysql>SELECT->DATE_FORMAT(t,'%M, %e,%Y') ASdate_sent,
->CONCAT(srcuser,'@',srchost) ASsender,
->CONCAT(dstuser,'@',dsthost) ASrecipient,
->size FROMmail;
+--------------+---------------+---------------+---------+|date_sent |sender |recipient |size |+--------------+---------------+---------------+---------+|May, 11,2006|barb@saturn|tricia@mars|58274||May, 12,2006|tricia@mars|gene@venus|194925||May, 12,2006|phil@mars|phil@saturn|1048||May, 13,2006|barb@saturn|tricia@venus|271||May, 14,2006|gene@venus|barb@mars|2291||May, 14,2006|phil@mars|tricia@saturn|5781||May, 14,2006|barb@venus|barb@venus|98151||May, 14,2006|tricia@saturn|phil@venus|2394482||May, 15,2006|gene@mars|gene@saturn|3824||May, 15,2006|phil@venus|phil@venus|978||May, 15,2006|gene@mars|tricia@saturn|998532||May, 15,2006|gene@saturn|gene@mars|3856||May, 16,2006|gene@venus|barb@mars|613||May, 16,2006|phil@venus|barb@venus|10294||May, 17,2006|phil@mars|tricia@saturn|873||May, 19,2006|gene@saturn|gene@venus|23992|+--------------+---------------+---------------+---------+16rows inset(0.00sec)
where语句中不可以使用别名
mysql第三天第7张mysql第三天第8张代码
mysql>SELECTt,srcuser,dstuser,size/1024ASkilobytes
->FROMmail WHEREsize/1024>500; #>前后需要空格不然报错
+---------------------+---------+---------+-----------+|t |srcuser |dstuser |kilobytes |+---------------------+---------+---------+-----------+|2006-05-1417:03:01|tricia |phil |2338.3613||2006-05-1510:25:52|gene |tricia |975.1289|+---------------------+---------+---------+-----------+2rows inset(0.00sec)
使用where语句与移除where语句的区别

没有where语句时,会遍历所有

其中‘0’ 是假

‘1’是真

mysql第三天第9张mysql第三天第10张代码
mysql>SELECTsrcuser,dstuser,size FROMmail WHEREsrcuser <'c'ANDsize >5000;
+---------+---------+-------+|srcuser |dstuser |size |+---------+---------+-------+|barb |tricia |58274||barb |barb |98151|+---------+---------+-------+2rows inset(0.00sec)

mysql
>SELECTsrcuser,srcuser >'c',dstuser,size, size >5000FROMmail;
+---------+---------------+---------+---------+-------------+|srcuser |srcuser >'c'|dstuser |size |size >5000|+---------+---------------+---------+---------+-------------+|barb |0|tricia |58274|1||tricia |1|gene |194925|1||phil |1|phil |1048|0||barb |0|tricia |271|0||gene |1|barb |2291|0||phil |1|tricia |5781|1||barb |0|barb |98151|1||tricia |1|phil |2394482|1||gene |1|gene |3824|0||phil |1|phil |978|0||gene |1|tricia |998532|1||gene |1|gene |3856|0||gene |1|barb |613|0||phil |1|barb |10294|1||phil |1|tricia |873|0||gene |1|gene |23992|1|+---------+---------------+---------+---------+-------------+16rows inset(0.00sec)
过滤重复信息,使得查询结果唯一化

DISTINCT

mysql第三天第11张mysql第三天第12张代码
mysql>SELECTsrcuser FROMmail;
+---------+|srcuser |+---------+|barb ||tricia ||phil ||barb ||gene ||phil ||barb ||tricia ||gene ||phil ||gene ||gene ||gene ||phil ||phil ||gene |+---------+16rows inset(0.00sec)

#使用DISTINCT
mysql
>SELECTDISTINCTsrcuser FROMmail;
+---------+|srcuser |+---------+|barb ||tricia ||phil ||gene |+---------+4rows inset(0.00sec)

统计不同结果个数 count()

mysql第三天第13张mysql第三天第14张代码
mysql>SELECTCOUNT(DISTINCTsrcuser) FROMmail;
+-------------------------+|COUNT(DISTINCTsrcuser) |+-------------------------+|4|+-------------------------+1row inset(0.00sec)

免责声明:文章转载自《mysql第三天》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇bat命令批处理判断32位还是64位系统的多种方法迅为-IMX6Q开发-非设备树uboot-修改默认环境变量下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

随便看看

layui 学习笔记(四) 复杂表头前台Excel导出

merges':mergeConf,'!cols':colConf,'!rows‘:rowConf}});}@...

virtuoso数据库的安装方法

数据库虚拟师有两种安装和配置方法。第一种方法是默认情况下直接在系统中安装virtualoso,复制virtualoso的安装文件,然后默认情况下将其直接安装。使用命令行对virtualoso数据库进行操作。1将virtualoso opensource解压缩到指定目录。例如,c:virtualoso2安装VC++2012和VC++2010插件补丁3以设置环境...

【问题】如何批量导出AI文件里内嵌的图片

截止目前为止,新版的AI里面没有直接可以批量导出内嵌图片的选项,手动一个个导出实在太麻烦了。有人说用Phantasm插件可以导出,但新版的找不到对应支持的插件版本,所以这里就不说了。这里介绍一种简单粗暴的方法。...

ios 苹果和百度地图的相关使用

同时由于苹果使用的是高德,不会像谷歌地图一样在国内乌龟一样的访问速度,确实做一些地图相关的东西,非常有吸引力。只是实现了显示一个百度地图的view。百度地图使用的是Objective-C++,这意味这必须要有一个.mm文件。...

mac下vscode插件位置

1、 位置:Mac:User/(您的用户名)/vscode/extensions II下vscode插件的存储位置。搜索步骤:以我的mac为例,打开查找器,单击远程CD,单击转到上面的文件夹,单击macintosh HD,单击用户(或用户),单击mymac,单击。vscode(.vscode是一个隐藏文件。如果默认情况下不显示,请按住ctrl+shift+....

Vue浏览器调试工具VueTools安装以及使用

ue-devtools是一款基于chrome浏览器的插件,用于vue应用的调试,这款vue调试神器可以极大地提高我们的调试效率。vue-devtools使用起来还是比较简单的,上手非常的容易,这里就细讲其使用说明了。安装方法二:这里以chrome浏览器为例:1、打开chrome网上应用店,搜索vue.js注:如果打不开页面需要代理选择第一个,点击添加至chr...