Winform开发框架之通用高级查询模块--SNF快速开发平台3.3-Spring.Net.Framework

  最近项目确实忙,但也是一直忙于有关项目和框架技术的事情,也一直致力于改善我的WInform开发框架.使得自己及客户使用起来更加方便,更加友好,更加高效。

在很多程序模块中都很常见,也是给客户扩展查询的一个很好的补充,由于我一直希望我的Winform开发框架能够精益求精,所以做了这个模块,希望对今后我自己所有的项目以及框架本身,都能高效的使用。

1、通用高级查询模块的用途及介绍

  既然称之为通用查询模块,那么他就不能与具体的表字段有耦合关系,但是要实现具体的查询,必须通过某种方式进行属性传递,实现更直观友好的字段查询功能。高级查询模块,在很多完善的程序上都会提供,用于满足用户对特定的字段,添加特定的条件进行,因为一般情况下,由于版面的限制界面上查询的内容比较有限,只是把一些很常见、重要的字段作为查询输入,如果表字段比较多,那么对有些特殊的字段就无所适从。

  

   如这个程序来讲 字段信息比较少不明显. 做为常用查询的字段一般情况下是不能太多字段的,因为那样页面显示的就会臃肿的难看。

   我的高级查询查询模块也是基于这个道理,因此,在主界面增加一个高级查询按钮入口,如上图所示,单击后,显示一个所有字段的列表,如下界面。

   

  看到上面这样是不是即熟悉又新其呢,新奇是因为以往做的高级查询是一个表格第一列是标题,第二行是输入的值再进行转换。而我这次做的是模仿用友的U9产品做的查询方案。即满足对高级查询的需要又扩展了查询方案进行保存。

   在介绍输入条件的时候,我们注意到,查询输入,基本上可以分为几类:其一是常规的文本类型,使用文本框控件;其二是表格翻译的列就采取了下拉列表控件进行展现;其三是日期类型,需要用户指定开始日期和结束日期,也就用了自定义日期范围控件(为了方便,都可以单独输入其中的一部分作为条件进行高级查询。);其四是数字类型,也是采用的文本框进行格式化,为什么不用范围而是可以选择查询的符号,这也是与其它人做高级查询的不同之处。其五,复选框我们也做了处理。

    查询后会保留用户的输入,第二次打开界面后,会加载之前的输入条件,这样比较人性化一些。同时可以保存查询方案,供下次登录系统选择查询方案就可以带出当时查询的条件,再次查询使用。另可以把查询方案共享给其它人,也可以只自己能看到。

2、通用高级查询模块的实现思路

    有很多人做的时候就根据表结构或者视图结构来做的,这样就会有一个限制就是在查询时用的不是表和视图,而是多表关联查询,高级查询的字段就会不全了,另原因表的字段很多不一定全部作为查询条件。

    我为了使用更简单更方便而我采取了从显示的内容来获取查询的字段进行处理。

    这样调用起来就很非常的简单,一行代码就搞定了。

  string whereSql = this.ShowAdvancedQuery(this.grvGridView);

    1.用传过来的gridView进行解析每一列使用的控件情况。

    

private void ShowQueryControl() 
        {
            foreach (GridColumn gridColumn in GridView.Columns)
            {
                string fieldName = gridColumn.FieldName;
                if (!fieldName.Equals(BusinessLogic.SelectedColumn))
                {
                    string name = gridColumn.Caption;
                    Type type = gridColumn.ColumnType;
                    。。。。。。。。。。
               }
           }
       }    

   2.在上面解析查询字段和控件的时候还需要查询的符号

   

#region 符号下拉列表
        int txtNotationWidth = 90;
        private ImageComboBoxEdit GetNotationImageComboBoxEdit(string fieldName) 
        {
            ImageComboBoxEdit comboBox = BaseInterfaceLogic.CreateImageComboBoxEdit("cmbNotation" + fieldName, null, null, txtNotationWidth, "Notation");//
            comboBox.Properties.Items.Clear();
            comboBox.Properties.Items.Add(new ImageComboBoxItem("包含", "Like"));
            comboBox.Properties.Items.Add(new ImageComboBoxItem("不包含", "NotLike"));
            comboBox.Properties.Items.Add(new ImageComboBoxItem("左包含", "StartWith"));
            comboBox.Properties.Items.Add(new ImageComboBoxItem("右包含", "EndWith"));
            
            comboBox.Properties.Items.Add(new ImageComboBoxItem("等于", "Equal"));
            comboBox.Properties.Items.Add(new ImageComboBoxItem("不等于", "NotEqual"));
            comboBox.Properties.Items.Add(new ImageComboBoxItem("大于", "Greater"));
            comboBox.Properties.Items.Add(new ImageComboBoxItem("小于", "Less"));
            comboBox.Properties.Items.Add(new ImageComboBoxItem("大于等于", "GreaterEqual"));
            comboBox.Properties.Items.Add(new ImageComboBoxItem("小于等于", "LessEqual"));
            comboBox.Properties.Items.Add(new ImageComboBoxItem("时间范围", "DateRange"));

            //comboBox.Properties.Items.Add(new ImageComboBoxItem("空", "Null"));
            //comboBox.Properties.Items.Add(new ImageComboBoxItem("非空", "NotNull"));
            //comboBox.Properties.Items.Add(new ImageComboBoxItem("两者之间", "Between"));
            comboBox.SelectedIndex = 0;
            return comboBox;
        }
        #endregion

   3.显示完成后,点击查询后需要从页面控件进行反解析处理

    下面是反解析条件的关键代码。

foreach (Control control in scrollableControlQuery.Controls)
            {
                if (control is FlowLayoutPanel)
                {
                    panel = (FlowLayoutPanel)control;
                    foreach (Control childControl in panel.Controls)
                    {
                        //05.普通下拉框
                        if (childControl is ImageComboBoxEdit)
                        {}
                    }
                }
          }

   4. 和普通查询功能并存

    为了使得传统查询按钮,和高级查询能够并存,我们需要存储一个高级查询的查询对象,但传统查询的时候,我们把高级查询对象设置为空即可屏蔽高级查询的条件了。

    在上面代码也可以看到,查询方案点击查询后只会返回组装好的sql条件给了 public string QueryWhere = string.Empty;属性。之后想要怎么使用就是程序说的算了。使我们的程序能够尽量满足客户的需求,获得更加好的反馈和支持了。

    项目中使用完整代码如下:

   

 #region 高级查询事件处理
        /// <summary>
        /// 高级查询事件处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSearchA_Click(object sender, EventArgs e)
        {
            string whereSql = this.ShowAdvancedQuery(this.grvGridView);
            if (!whereSql.Equals(ShowAdvancedQueryCancel))
            {
                this.Search(whereSql);
            }
            
        }
        #endregion

  从上面来看,其实我这次做的高级查询在行业内是比较简单实用的。而且还增加了查询方案进行存储。也算是行内比较标准的做法了。其它人可以进行效仿了。

  当然这个查询方案还不满足于现在的功能,之后还要扩展排序规则和显示的栏目控制。

-------------------------------------------------------------------------------------------

作者: 王春天 2015-10-21
作者Blog:http://www.cnblogs.com/spring_wang 出处: http://www.cnblogs.com/spring_wang/p/4874584.html

  如果觉得还不错,欢迎转载。

SNF快速开发平台框架的系列文章:

SNF开发平台WinForm之五-高级查询使用说明-http://www.cnblogs.com/spring_wang/p/6116640.html

SNF开发平台WinForm之四-开发-主细表管理页面-http://www.cnblogs.com/spring_wang/p/6116626.html

SNF开发平台WinForm之三-开发-单表选择控件创建-http://www.cnblogs.com/spring_wang/p/6116592.html

SNF开发平台WinForm之二-开发-单表表单管理页面-http://www.cnblogs.com/spring_wang/p/6116572.html

SNF开发平台WinForm之一-开发-单表表格编辑管理页面-http://www.cnblogs.com/spring_wang/p/6116523.html

Winform开发框架之通用高级查询模块--SNF快速开发平台3.3-Spring.Net.Framework

Winform开发框架之图表报表在线设计器2-图表-SNF.EasyQuery项目--SNF快速开发平台3.3-Spring.Net.Framework

Winform开发框架之图表报表在线设计器-报表-SNF.EasyQuery项目--SNF快速开发平台3.3-Spring.Net.Framework(

Winform开发框架之通用附件管理模块 --SNF快速开发平台3.3-Spring.Net.Framework

SNFAutoupdater通用自动升级组件V2.0-WinForm

SNF快速开发平台3.2之--.Net可扩展的单据编号生成器-SNF.CodeRule

SNF快速开发平台3.1之--审核流(3)低调奢华,简单不凡,实例演示-SNF.WorkFlow

SNF快速开发平台3.1之--审核流(2)流程设计-SNF.WorkFlow功能使用说明

SNF快速开发平台3.1之--审核流(1)SNF.WorkFlow审核流简介

SNF快速开发平台3.0之--完美的代码生成器SNF.CodeGenerator-快速开发者的利器

基于MVC4+EasyUI的Web开发框架--Spring.Net.FrameworkV3.0总体介绍

SNF快速开发平台3.0之--MVC 打印解决方案

SNF快速开发平台3.0之--文件批量上传-统一附件管理器-在线预览文件(有互联网和没有两种)

SNF快速开发平台3.0之--asp.net mvc4 强大的导出和不需要上传文件的批量导入EXCEL

SNF快速开发平台3.0之MVC通用控件库展示-Asp.net+MVC4.0+WebAPI+EasyUI+Knockout

SNF快速开发平台3.0之BS页面展示和九大优点-部分页面显示效果-Asp.net+MVC4.0+WebAPI+EasyUI +Knockout

SNF快速开发平台3.0之-界面个性化配置+10种皮肤+7种菜单-Asp.net+MVC4.0+WebAPI+EasyUI+Knockout

SNF快速开发平台3.0之-CS页面-Asp.net+Spring.Net.Framework

SNF快速开发平台3.0之--系统里广播的作用--迅速及时、简明扼要的把信息发送给接收者

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
全新RDIFramework.NET V5.1版本发布。降低开发成本,提高产品质量,提升用户体验与开发团队稳定性,做软件就选RDIFramework.NET敏捷开发框架。 RDIFramework.NET敏捷开发框架,是我司重磅推出的基于全新.NET Framework.NET Core的快速信息化系统开发、整合框架,为企业快速构建跨平台、企业级的应用提供了强大支持。 开发人员不需要开发系统的基础功能和公共模块,框架自身提供了强大的函数库和开发包,开发人员只需集中精力专注于业务部分的开发,因此大大提高开发效率和节约开发成本。框架采用主流的C#语言开发完成,支持多种数据库类型,支持Web、WinForm,支持Framework与Core双引擎。 使用RDIFramework.NET敏捷开发框架能提高管理类软件系统的整体质量、提高模块模块之间的兼容性、提高代码的重复利用率,使软件系统架构更加合理、质量更加过硬,使得劳动成果最大程度上重复利用。 框架基础模块包括:强大灵活的权限控制组件,模块分配与管理组件,灵活易用的工作流组件、数据字典管理组件、在线表单设计组件、丰富的报表统计组件、即时通讯(IM)组件、邮件中心组件、微信开发相关组件、任务调度组件、自动升级组件、多语言模块,各种常用的商业控件,强大的代码生成器,开发实例、丰富的基础类库、开发辅助工具等各基础常用功能组件。 框架提供的大量通用插件,支持Saas多租户模式,完成功能的开发就像搭积木一样,只需要把各种组件进行组合拼装,拼装好了系统的开发也就完成了。应用系统建立在此框架之上,采用构件式、可复用开发,节省开发成本,加快开发速度,在软件开发上更好的做到多快省。 适合低中高任意开发水平的开发者,可以开发OA、ERP、BPM、CRM、WMS、TMS、MIS、BI、电商平台后台、物流管理系统、医院管理系统、快递管理系统、教务管理系统等各类管理软件、支持大并发、SaaS应用。代码稳定、组件丰富、功能强大、无限扩展。由框架开发团队的原班人马直接提供技术支持,为您顺利完成开发工作保驾护航。不管您是零基础还是专业开发人员,都能轻松驾驭这套开发框架。 ------------------------------------------------------------------------------------------------------------------ 一路走来数个年头,感谢RDIFramework.NET框架的支持者与使用者,大家可以通过下面的地址了解详情。 RDIFramework.NET官方网站:http://www.rdiframework.net/ RDIFramework.NET官方博客:http://blog.rdiframework.net/ 特别说明,框架相关的技术文章请以官方网站为准,欢迎大家收藏! RDIFramework.NET框架由海南国思软件科技有限公司专业团队长期打造、一直在更新、一直在升级,请放心使用! 欢迎关注RDIFramework.NET框架官方微信公众号(微信号:guosisoft),及时了解最新动态。
SunnyUI.Net 是基于.Net Framework 4.0+、.Net Core3.1、.Net 5 框架的 C# WinForm 开源控件库、工具类库、扩展类库、多页面开发框架。 源码编译环境:VS2019 16.8+,.Net5,.Net Core3.1 动态库应用环境:VS2010及以上,.Net Framework 4.0及以上(不包括.Net Framework 4 Client Profile),.Net Core 3.1,.Net 5.0 推荐通过Nuget安装:Install-Package SunnyUI,或者通过Nuget搜索SunnyUI安装。 软件介绍: 1、开源控件库 基于.Net Framework4.0,原生控件开发,参考 Element主题风格,包含 按钮、编辑框、下拉框、数据表格、工控仪表、统计图表在内的常用控件超过 50 个,满足常规开发需求,每个控件都精雕细琢,注重细节; 包含 Element 风格主题 11 个,其他主题 6 个,包含主题管理组件 UIStyleManager,可自由切换主题。 2、工具库 收集整理开发过程中经常用到的工具类库。 3、扩展库 收集整理开发过程中经常用到的扩展类库。 4、多页面框架 参考Element,包括7种常用框架风格,只需几行简单的代码即可创建多页面程序,其支撑组件包括UIForm,UIPage,UIFrame,集合常用控件库即可快速开发WinForm应用程序。 SunnyUI.Net开发框架 更新日志: v3.0.2 UIMarkLabel:增加带颜色标签的Label UIRoundProcess:圆形滚动条 UIBreadcrumb:增加面包屑导航 UILedLabel:增加Led标签 UIHeaderButton:在工具箱中显示 UILineChart:支持拖拽选取放大 UIDateTimePicker:修复下拉选择日期后关闭的Bug UINavMenu:增加设置二级菜单底色 UIColorPicker:增加单击事件以选中颜色 UITitlePage:增加ShowTitle可控制是否显示标题 UINavBar:增加可设置背景图片 框架增加IFrame接口,方便页面跳转 UIDataGridView:修改垂直滚动条和原版一致,并增加翻页方式滚动 UIPagination: 修正因两次查询数量相等而引起的不刷新 UIHeaderButton: 增加字体图标背景时鼠标移上背景色 UITabControl:修改第一个TabPage关不掉的Bug UIDataGridView:增加EnterAsTab属性,编辑输入时,用Enter键代替Tab键跳到下一个单元格 UILineChart:增加鼠标框选放大,可多次放大,右键点击恢复一次,双击恢复 UITitlePanel:修复OnMouseMove事件 UITrackBar:增加垂直显示方式 UIFlowLayoutPanel:修改了一处因为其加入控件大小发生变化而引起的滚动条出错。
--高级查询在数据库中用得是最频繁的,也是应用最广泛的。 Ø 基本常用查询 --select select * from student; --all 查询所有 select all sex from student; --distinct 过滤重复 select distinct sex from student; --count 统计 select count(*) from student; select count(sex) from student; select count(distinct sex) from student; --top 取前N条记录 select top 3 * from student; --alias column name 列重命名 select id as 编号, name '名称', sex 性别 from student; --alias table name 表重命名 select id, name, s.id, s.name from student s; --column 列运算 select (age + id) col from student; select s.name + '-' + c.name from classes c, student s where s.cid = c.id; --where 条件 select * from student where id = 2; select * from student where id > 7; select * from student where id < 3; select * from student where id <> 3; select * from student where id >= 3; select * from student where id <= 5; select * from student where id !> 3; select * from student where id !< 5; --and 并且 select * from student where id > 2 and sex = 1; --or 或者 select * from student where id = 2 or sex = 1; --between ... and ... 相当于并且 select * from student where id between 2 and 5; select * from student where id not between 2 and 5; --like 模糊查询 select * from student where name like '%a%'; select * from student where name like '%[a][o]%'; select * from student where name not like '%a%'; select * from student where name like 'ja%'; select * from student where name not like '%[j,n]%'; select * from student where name like '%[j,n,a]%'; select * from student where name like '%[^ja,as,on]%'; select * from student where name like '%[ja_on]%'; --in 子查询 select * from student where id in (1, 2); --not in 不在其中 select * from student where id not in (1, 2); --is null 是空 select * from student where age is null; --is not null 不为空 select * from student where age is not null; --order by 排序 select * from student order by name; select * from student order by name desc; select * from student order by name asc; --group by 分组 按照年龄进行分组统计 select count(age), age from student group by age; 按照性别进行分组统计 select count(*), sex from student group by sex; 按照年龄和性别组合分组统计,并排序 select count(*), sex from student group by sex, age order by age; 按照性别分组,并且是id大于2的记录最后按照性别排序 select count(*), sex from student where id > 2 group by sex order by sex; 查询id大于2的数据,并完成运算后的结果进行分组和排序 select count(*), (sex * id) new from student where id > 2 group by sex * id order by sex * id; --group by all 所有分组 按照年龄分组,是所有的年龄 select count(*), age from student group by all age; --having 分组过滤条件 按照年龄分组,过滤年龄为空的数据,并且统计分组的条数和现实年龄信息 select count(*), age from student group by age having age is not null; 按照年龄和cid组合分组,过滤条件是cid大于1的记录 select count(*), cid, sex from student group by cid, sex having cid > 1; 按照年龄分组,过滤条件是分组后的记录条数大于等于2 select count(*), age from student group by age having count(age) >= 2; 按照cid和性别组合分组,过滤条件是cid大于1,cid的最大值大于2 select count(*), cid, sex from student group by cid, sex having cid > 1 and max(cid) > 2; Ø 嵌套子查询查询是一个嵌套在select、insert、update或delete语句或其他子查询中的查询。任何允许使用表达式的地方都可以使用子查询。子查询也称为内部查询或内部选择,而包含子查询的语句也成为外部查询或外部选择。 # from (select … table)示例 将一个table的查询结果当做一个新表进行查询 select * from ( select id, name from student where sex = 1 ) t where t.id > 2; 上面括号中的语句,就是子查询语句(内部查询)。在外面的是外部查询,其中外部查询可以包含以下语句: 1、 包含常规选择列表组件的常规select查询 2、 包含一个或多个表或视图名称的常规from语句 3、 可选的where子句 4、 可选的group by子句 5、 可选的having子句 # 示例 查询班级信息,统计班级学生人生 select *, (select count(*) from student where cid = classes.id) as num from classes order by num; # in, not in子句查询示例 查询班级id大于小于的这些班级的学生信息 select * from student where cid in ( select id from classes where id > 2 and id < 4 ); 查询不是班的学生信息 select * from student where cid not in ( select id from classes where name = '2班' ) in、not in 后面的子句返回的结果必须是一列,这一列的结果将会作为查询条件对应前面的条件。如cid对应子句的id; # exists和not exists子句查询示例 查询存在班级id为的学生信息 select * from student where exists ( select * from classes where id = student.cid and id = 3 ); 查询没有分配班级的学生信息 select * from student where not exists ( select * from classes where id = student.cid ); exists和not exists查询需要内部查询和外部查询进行一个关联的条件,如果没有这个条件将是查询到的所有信息。如:id等于student.id; # some、any、all子句查询示例 查询班级的学生年龄大于班级的学生的年龄的信息 select * from student where cid = 5 and age > all ( select age from student where cid = 3 ); select * from student where cid = 5 and age > any ( select age from student where cid = 3 ); select * from student where cid = 5 and age > some ( select age from student where cid = 3 ); Ø 聚合查询 1、 distinct去掉重复数据 select distinct sex from student; select count(sex), count(distinct sex) from student; 2、 compute和compute by汇总查询 对年龄大于的进行汇总 select age from student where age > 20 order by age compute sum(age) by age; 对年龄大于的按照性别进行分组汇总年龄信息 select id, sex, age from student where age > 20 order by sex, age compute sum(age) by sex; 按照年龄分组汇总 select age from student where age > 20 order by age, id compute sum(age); 按照年龄分组,年龄汇总,id找最大值 select id, age from student where age > 20 order by age compute sum(age), max(id); compute进行汇总前面是查询的结果,后面一条结果集就是汇总的信息。compute子句中可以添加多个汇总表达式,可以添加的信息如下: a、 可选by关键字。它是每一列计算指定的行聚合 b、 行聚合函数名称。包括sum、avg、min、max、count等 c、 要对其执行聚合函数的列 compute by适合做先分组后汇总的业务。compute by后面的列一定要是order by中出现的列。 3、 cube汇总 cube汇总和compute效果类似,但语法较简洁,而且返回的是一个结果集。 select count(*), sex from student group by sex with cube; select count(*), age, sum(age) from student where age is not null group by age with cube; cube要结合group by语句完成分组汇总 Ø 排序函数 排序在很多地方需要用到,需要对查询结果进行排序并且给出序号。比如: 1、 对某张表进行排序,序号需要递增不重复的 2、 对学生的成绩进行排序,得出名次,名次可以并列,但名次的序号是连续递增的 3、 在某些排序的情况下,需要跳空序号,虽然是并列 基本语法 排序函数 over([分组语句] 排序子句[desc][asc]) 排序子句 order by 列名, 列名 分组子句 partition by 分组列, 分组列 # row_number函数 根据排序子句给出递增连续序号 按照名称排序的顺序递增 select s.id, s.name, cid, c.name, row_number() over(order by c.name) as number from student s, classes c where cid = c.id; # rank函数函数 根据排序子句给出递增的序号,但是存在并列并且跳空 顺序递增 select id, name, rank() over(order by cid) as rank from student; 跳过相同递增 select s.id, s.name, cid, c.name, rank() over(order by c.name) as rank from student s, classes c where cid = c.id; # dense_rank函数 根据排序子句给出递增的序号,但是存在并列不跳空 不跳过,直接递增 select s.id, s.name, cid, c.name, dense_rank() over(order by c.name) as dense from student s, classes c where cid = c.id; # partition by分组子句 可以完成对分组的数据进行增加排序,partition by可以与以上三个函数联合使用。 利用partition by按照班级名称分组,学生id排序 select s.id, s.name, cid, c.name, row_number() over(partition by c.name order by s.id) as rank from student s, classes c where cid = c.id; select s.id, s.name, cid, c.name, rank() over(partition by c.name order by s.id) as rank from student s, classes c where cid = c.id; select s.id, s.name, cid, c.name, dense_rank() over(partition by c.name order by s.id) as rank from student s, classes c where cid = c.id; # ntile平均排序函数 将要排序的数据进行平分,然后按照等分排序。ntile中的参数代表分成多少等分。 select s.id, s.name, cid, c.name, ntile(5) over(order by c.name) as ntile from student s, classes c where cid = c.id; Ø 集合运算 操作两组查询结果,进行交集、并集、减集运算 1、 union和union all进行并集运算 --union 并集、不重复 select id, name from student where name like 'ja%' union select id, name from student where id = 4; --并集、重复 select * from student where name like 'ja%' union all select * from student; 2、 intersect进行交集运算 --交集(相同部分) select * from student where name like 'ja%' intersect select * from student; 3、 except进行减集运算 --减集(除相同部分) select * from student where name like 'ja%' except select * from student where name like 'jas%'; Ø 公式表表达式 查询表的时候,有时候中间表需要重复使用,这些子查询被重复查询调用,不但效率低,而且可读性低,不利于理解。那么公式表表达式可以解决这个问题。 我们可以将公式表表达式(CET)视为临时结果集,在select、insert、update、delete或是create view语句的执行范围内进行定义。 --表达式 with statNum(id, num) as ( select cid, count(*) from student where id > 0 group by cid ) select id, num from statNum order by id; with statNum(id, num) as ( select cid, count(*) from student where id > 0 group by cid ) select max(id), avg(num) from statNum; Ø 连接查询 1、 简化连接查询 --简化联接查询 select s.id, s.name, c.id, c.name from student s, classes c where s.cid = c.id; 2、 left join左连接 --左连接 select s.id, s.name, c.id, c.name from student s left join classes c on s.cid = c.id; 3、 right join右连接 --右连接 select s.id, s.name, c.id, c.name from student s right join classes c on s.cid = c.id; 4、 inner join内连接 --内连接 select s.id, s.name, c.id, c.name from student s inner join classes c on s.cid = c.id; --inner可以省略 select s.id, s.name, c.id, c.name from student s join classes c on s.cid = c.id; 5、 cross join交叉连接 --交叉联接查询,结果是一个笛卡儿乘积 select s.id, s.name, c.id, c.name from student s cross join classes c --where s.cid = c.id; 6、 自连接(同一张表进行连接查询) --自连接 select distinct s.* from student s, student s1 where s.id <> s1.id and s.sex = s1.sex; Ø 函数 1、 聚合函数 max最大值、min最小值、count统计、avg平均值、sum求和、var求方差 select max(age) max_age, min(age) min_age, count(age) count_age, avg(age) avg_age, sum(age) sum_age, var(age) var_age from student; 2、 日期时间函数 select dateAdd(day, 3, getDate());--加天 select dateAdd(year, 3, getDate());--加年 select dateAdd(hour, 3, getDate());--加小时 --返回跨两个指定日期的日期边界数和时间边界数 select dateDiff(day, '2011-06-20', getDate()); --相差秒数 select dateDiff(second, '2011-06-22 11:00:00', getDate()); --相差小时数 select dateDiff(hour, '2011-06-22 10:00:00', getDate()); select dateName(month, getDate());--当前月份 select dateName(minute, getDate());--当前分钟 select dateName(weekday, getDate());--当前星期 select datePart(month, getDate());--当前月份 select datePart(weekday, getDate());--当前星期 select datePart(second, getDate());--当前秒数 select day(getDate());--返回当前日期天数 select day('2011-06-30');--返回当前日期天数 select month(getDate());--返回当前日期月份 select month('2011-11-10'); select year(getDate());--返回当前日期年份 select year('2010-11-10'); select getDate();--当前系统日期 select getUTCDate();--utc日期 3、 数学函数 select pi();--PI函数 select rand(100), rand(50), rand(), rand();--随机数 select round(rand(), 3), round(rand(100), 5);--精确小数位 --精确位数,负数表示小数点前 select round(123.456, 2), round(254.124, -2); select round(123.4567, 1, 2);

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值