l14107cb 发表于 2024-8-4 15:42:10

Excel中运用SQL查询语句,让你工作中的数据分析如虎添翼


    <div style="color: black; text-align: left; margin-bottom: 10px;">
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">在<span style="color: black;">咱们</span>进行数据处理的过程中,<span style="color: black;">咱们</span>常常会调用<span style="color: black;">有些</span><span style="color: black;">外边</span>数据,此时<span style="color: black;">运用</span>SQL<span style="color: black;">查找</span>语句是非常方便的,今天<span style="color: black;">咱们</span>就来给<span style="color: black;">大众</span><span style="color: black;">仔细</span>讲解一下SQL<span style="color: black;">查找</span>语句中用得最多的SELECT语句的<span style="color: black;">有些</span>基本用法。</p>
      <h1 style="color: black; text-align: left; margin-bottom: 10px;">1.SELECT 语法</h1>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">SELECT</strong> </p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">{|talbe.|field1[,field2[,…]]}</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">FROM</strong> table_source</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">[ WHERE search_condition ]</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">[ GROUP BY group_by_expression ]</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">[ HAVING search_condition ]</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">[ ORDER BY order_expression [ ASC | DESC ] ]</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> rows | rows OFFSET offset]</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">DISTINCT<strong style="color: blue;"> 去除重复值</strong></p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">DISTINCTROW<strong style="color: blue;">忽略基于<span style="color: black;">全部</span>重复记录的数据,而<span style="color: black;">不仅</span>是重复字段。</strong></p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">执行<span style="color: black;">过程</span>:</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">1.先从from字句一个表或多个表创建工作表</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">2.将where<span style="color: black;">要求</span>应用于1)的工作表,<span style="color: black;">保存</span>满足<span style="color: black;">要求</span>的行</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">3.GroupBy 将2)的结果分成多个组</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">4.Having 将<span style="color: black;">要求</span>应用于3)组合的<span style="color: black;">要求</span>过滤,只<span style="color: black;">保存</span>符合<span style="color: black;">需求</span>的组。</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">5.Order By对结果进行排序。</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">6. LIMIT限制<span style="color: black;">查找</span>的条数</p>
      <h1 style="color: black; text-align: left; margin-bottom: 10px;">2.FROM子句</h1>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">FROM子句是SELECT语句中<span style="color: black;">必要</span>要有的一部分,它指定了<span style="color: black;">查找</span>所<span style="color: black;">必须</span>的数据源的名<span style="color: black;">叫作</span>。</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">语法:FROM table_source。</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">参数解释:table_source<span style="color: black;">能够</span>是表、视图等等,一个语句中最多<span style="color: black;">能够</span><span style="color: black;">运用</span>256个表源。<span style="color: black;">倘若</span><span style="color: black;">运用</span>的表<span style="color: black;">太多</span>,<span style="color: black;">查找</span>性能是会受到影响的,<span style="color: black;">因此</span>不<span style="color: black;">意见</span><span style="color: black;">运用</span>太多表源。</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">请看下面的示例:</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">Select distinct 供货商信息.单位名<span style="color: black;">叫作</span>,供货商信息.<span style="color: black;">位置</span> from 供货商信息</strong></p>
      <h1 style="color: black; text-align: left; margin-bottom: 10px;">3.WHERE子句</h1>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">在<span style="color: black;">查找</span>数据的时候,<span style="color: black;">咱们</span>常常是<span style="color: black;">期盼</span><span style="color: black;">查找</span>出满足<span style="color: black;">必定</span><span style="color: black;">要求</span>的数据,而非数据表中的所有数据,这个时候<span style="color: black;">咱们</span>就<span style="color: black;">能够</span><span style="color: black;">运用</span>WHERE子句来实现。数据库系统处理该语句时,按<span style="color: black;">行径</span>单位,逐个<span style="color: black;">检测</span><span style="color: black;">每一个</span>行<span style="color: black;">是不是</span>满足<span style="color: black;">要求</span>,将不满足<span style="color: black;">要求</span>的行筛选掉。</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">语法:WHERE search_conditions</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">参数解释:search_conditions为用户所选所<span style="color: black;">必须</span><span style="color: black;">查找</span>数据行的<span style="color: black;">要求</span>,即<span style="color: black;">查找</span>返回行记录的满足<span style="color: black;">要求</span>。</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">3.1 比较运算符</strong></p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">3.2 <span style="color: black;">规律</span>运算符</strong></p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">3.3 字符匹配符</strong></p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">在WHERE子句中 <span style="color: black;">运用</span>字符匹配符LIKE或NOT LIKE <span style="color: black;">能够</span>把表达式与字符串进行比较,从而实现对字符串的模糊<span style="color: black;">查找</span>。</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">语法:WHERE expression LIKE string</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">参数解释:为可选项,string<span style="color: black;">暗示</span>进行比较的字符串。WHERE子句实现对字符串的模糊匹配,进行模糊匹配是在string字符串中<span style="color: black;">运用</span>通配符。</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">示例:Select * from 入库数据 where <span style="color: black;">制品</span>名<span style="color: black;">叫作</span> like % a %</strong></p>
      <h1 style="color: black; text-align: left; margin-bottom: 10px;">4.ORDER BY 子句</h1>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">有些时候,<span style="color: black;">咱们</span><span style="color: black;">期盼</span><span style="color: black;">查找</span>出来的结果是<span style="color: black;">根据</span>某个<strong style="color: blue;"><span style="color: black;">次序</span><span style="color: black;">摆列</span></strong>的,这个时候就<span style="color: black;">能够</span><span style="color: black;">运用</span>ORDER BY子句对生成的结果集进行排序。</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">语法:ORDER BY order_experssion</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">参数解释:order_experssion<span style="color: black;">暗示</span>用于排序的列或列名及表达式。当有多个排序列时,<span style="color: black;">每一个</span>排序列用逗号隔开,<span style="color: black;">况且</span>列后都<span style="color: black;">能够</span>跟一个排序<span style="color: black;">需求</span>。ASC—–升序排序(默认值),DESC—降序排序。</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">示例:Select * from 入库数据 order by <span style="color: black;">制品</span>名<span style="color: black;">叫作</span> desc</strong></p>
      <h1 style="color: black; text-align: left; margin-bottom: 10px;">5.GROUP BY 子句</h1>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">在<span style="color: black;">查找</span>中,有时候<span style="color: black;">咱们</span><span style="color: black;">必须</span>对数据进行分组(类似于Excel中的<span style="color: black;">归类</span>汇总的功能),此时就<span style="color: black;">能够</span><span style="color: black;">运用</span>GROUP BY 子句。</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">语法:GROUP BY group_by_expression[ WITH ROLLUP|CUBE ]</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">参数解释:group_by_expression<span style="color: black;">暗示</span>分组所依据的列,ROLLUP<span style="color: black;">暗示</span>只返回<span style="color: black;">第1</span>个分组<span style="color: black;">要求</span>指定的列的统计行,若改变列的<span style="color: black;">次序</span>就会使返回的结果行数据<span style="color: black;">出现</span>变化。CUBE是ROLLUP的扩展,<span style="color: black;">暗示</span>除了返回由GROUP BY子句指定的列外,还返回按组统计的行。GROUP BY 子句<span style="color: black;">一般</span>与统计函数联合<span style="color: black;">运用</span>。<span style="color: black;">平常</span>的统计函数如下表:</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">示例:<strong style="color: blue;">Select count(*)from 入库数据 group by <span style="color: black;">制品</span>名<span style="color: black;">叫作</span></strong></p>
      <h1 style="color: black; text-align: left; margin-bottom: 10px;">6.HAVING</h1>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">HAVING子句的用法类似WHERE子句,它指定了组或集合的搜索<span style="color: black;">要求</span>。HAVING子句<span style="color: black;">一般</span>与GROUP BY子句<span style="color: black;">一块</span><span style="color: black;">运用</span>。</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">语法:HAVING search_conditions</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">参数解释:search_conditions为<span style="color: black;">查找</span>所需的<span style="color: black;">要求</span>,即返回<span style="color: black;">查找</span>结果的满足<span style="color: black;">要求</span>。在<span style="color: black;">运用</span>GROUP BY 子句时,HAVING子句将限定<span style="color: black;">全部</span>GROUP BY子句创建的组。其<span style="color: black;">详细</span>规则如下:</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">1.<span style="color: black;">倘若</span>指定了GROUP BY 子句,则HAVING 子句的<span style="color: black;">查找</span><span style="color: black;">要求</span>应用于GROUP BY子句创建的组</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">2.<span style="color: black;">倘若</span>指定了WHERE子句而<span style="color: black;">无</span>指定GROUP BY子句,则HAVING子句的<span style="color: black;">查找</span><span style="color: black;">要求</span>将应用于WHERE子句的输出结果集</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">3. <span style="color: black;">倘若</span>既<span style="color: black;">无</span>指定WHERE子句又<span style="color: black;">无</span>指定GROUP BY子句,则HAVING子句的<span style="color: black;">查找</span><span style="color: black;">要求</span>将用于FROM子句的输出结果集</p>
      <h1 style="color: black; text-align: left; margin-bottom: 10px;">7.limit子句</h1>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">其<span style="color: black;">功效</span>是用于限制<span style="color: black;">查找</span>结果的条数。常常用于实现分页<span style="color: black;">查找</span>。</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">语法: rows | rows OFFSET offset]</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">参数解释:有两个参数,<span style="color: black;">第1</span>个是偏移量,第二个是数目。</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">Acces及Excel的数据库不支持该语句。</p>
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">示例:Select * from 入库数据 limit 2,2</strong></p>
    </div>




Myramillan 发表于 2024-9-8 21:40:57

我完全同意你的观点,说得太对了。

b1gc8v 发表于 2024-10-24 14:16:01

我们有着相似的经历,你的感受我深有体会。

7wu1wm0 发表于 2024-11-5 10:00:29

楼主的文章深得我心,表示由衷的感谢!

b1gc8v 发表于 2024-11-13 11:05:15

我们有着相似的经历,你的感受我深有体会。
页: [1]
查看完整版本: Excel中运用SQL查询语句,让你工作中的数据分析如虎添翼