1. Example as below:
# 1. Goods table select * from goods; +----------+--------+------------+ | goods_id | cat_id | goods_name | +----------+--------+------------+ | 1 | 1 | CDMA Phone | | 2 | 1 | GSM Phone | | 3 | 1 | 3G Phone | +----------+--------+------------+ # 2. Cat table select * from cat; +--------+--------------+ | cat_id | cat_name | +--------+--------------+ | 1 | Mobile Phone | +--------+--------------+ # 3. How to combine cat_name into goods table? # First approach: # Using JAVA, select all from goods and get cat_id, then search cat table and get cat_name. Combine results. # Using m*n times SQL # Second approach: # Using join(left join) # select goods_id, goods_name, cat.cat_name from *** where goods.cat_id = cat.cat_id; # But how to realize this?
2. Set/Collection in Math
1) Properties of Set: Orderless, Uniquity
# Orderless #{1, 2, 3} == {2, 3, 1} == {1, 3, 2} # Uniquity # {1, 2, 3, 3} is not a Set
2) Regard a table as a set, and a row in a table as an element in a set.
So seriously speaking, there can not be two same rows in a single table.
But actually, there can be two same rows in a single table because there is a rowId for each row in a table. And the rowId is not visible. It is generated by MySQL automatically and can not be accessed by user.
3. Cartesian Product in Math
# Eg 1 # What's the cartesian product of the two following sets? # Q: {2, 3, 4} X {4, 7} # A: {8, 14, 12, 21, 16, 28}--->Wrong! # A: {{2, 4}, {2, 7}, {3, 4}, {3, 7}, {4, 4}, {4, 7}}--->Bingo! #Eg 2 # What's the cartesian product of the two following sets # Q: {chicken, duck} X {cat, dog, camel} # A: {{chicken, cat}, {chicken, dog}, {chicken, camel}, {duck, cat}, {duck, dog}, {duck, camel}}
1) Cartesian product is also called Set multiple.
2) Cartesian product is actually a total combination of the two sets.
Q: Let set A have M elements which are unique in set A; Let set B have N elements which are unique in set B. So how many element will we get after cartesian product of A and B?
A: The number is M*N. And if we put these M*N elements in a set there will not be duplicate elements to worry about
. Q: If table A have 9 columns and table B have 5 columns. What's the cartesian product of the two tables?
A: There will be 9*5=45 columns.
Eg:
Cartesian product of two tables (Refer from IBM red brick warehouse website)
Join of two tables
FL | Jacksonville | South | |
FL | Miami | South | |
TN | New Orleans | South |
Example query
select * from state, region;
Cartesian product (join predicate not specified)
FL | Jacksonville | South |
FL | Miami | South |
FL | New Orleans | South |
FL | Jacksonville | South |
FL | Miami | South |
FL | New Orleans | South |
TN | Jacksonville | South |
TN | Miami | South |
TN | New Orleans | South |
Eg
#Cartesian product of two tables select * from goods, cat; +----------+--------+------------+--------+--------------+ | goods_id | cat_id | goods_name | cat_id | cat_name | +----------+--------+------------+--------+--------------+ | 1 | 1 | CDMA Phone | 1 | Mobile Phone | | 2 | 1 | GSM Phone | 1 | Mobile Phone | | 3 | 1 | 3G Phone | 1 | Mobile Phone | +----------+--------+------------+--------+--------------+ #A possible solution to the question raised at begining select * from goods, cat where goods.cat_id = cat.cat_id; +----------+--------+------------+--------+--------------+ | goods_id | cat_id | goods_name | cat_id | cat_name | +----------+--------+------------+--------+--------------+ | 1 | 1 | CDMA Phone | 1 | Mobile Phone | | 2 | 1 | GSM Phone | 1 | Mobile Phone | | 3 | 1 | 3G Phone | 1 | Mobile Phone | +----------+--------+------------+--------+--------------+ #Two Steps: #1. Get cartesian product of two tables #2. Apply filters to the result set. #A more elegant way by using left join select * from goods left join cat on goods.cat_id = cat.cat_id; +----------+--------+------------+--------+--------------+ | goods_id | cat_id | goods_name | cat_id | cat_name | +----------+--------+------------+--------+--------------+ | 1 | 1 | CDMA Phone | 1 | Mobile Phone | | 2 | 1 | GSM Phone | 1 | Mobile Phone | | 3 | 1 | 3G Phone | 1 | Mobile Phone | +----------+--------+------------+--------+--------------+ #Remove duplicate columns select goods.cat_id, goods_id, goods_name from goods left join cat on goods.cat_id = cat.cat_id; +--------+----------+------------+ | cat_id | goods_id | goods_name | +--------+----------+------------+ | 1 | 1 | CDMA Phone | | 1 | 2 | GSM Phone | | 1 | 3 | 3G Phone | +--------+----------+------------+
1) Regard the result of cartesian product or left join as a real table and not as a result set.
2) We can use where, group by, having, order by, limit on this result table.
Eg.
select goods.cat_id, goods_id, goods_name from goods left join cat on goods.cat_id = cat.cat_id where goods_id >= 2; +--------+----------+------------+ | cat_id | goods_id | goods_name | +--------+----------+------------+ | 1 | 2 | GSM Phone | | 1 | 3 | 3G Phone | +--------+----------+------------+
相关推荐
##### 示例1:笛卡尔积(Cartesian Product) 笛卡尔积是指在没有指定任何连接条件的情况下,两个表之间的所有可能组合。例如,在MySQL中,如果我们执行以下查询: ```sql SELECT * FROM user_sal s1 JOIN user_sal ...
2. **关系代数**:它是对关系数据库操作的一种抽象表示,包括选择(SELECT)、投影(PROJECT)、并集(UNION)、差集(MINUS)、笛卡尔积(CARTESIAN PRODUCT)、连接(JOIN)和除法(DIVIDE)等操作。理解这些操作...
关系代数操作主要包括选择(Selection)、投影(Projection)、并集(Union)、差集(Difference)、笛卡尔积(Cartesian Product)、重命名(Rename)以及连接(Join)等。通过这些基本操作,可以构建出复杂的查询...
作业可能涉及到选择(SELECT)、投影(PROJECT)、并集(UNION)、差集(MINUS)、笛卡尔积(CARTESIAN PRODUCT)、连接(JOIN)等基本操作。理解关系代数有助于深入理解SQL查询的工作原理。 3. **作业二建立数据库...
基于的手势识别系统可控制灯的亮_3
untitled2.zip
S7-1500和分布式外围系统ET200MP模块数据
anaconda配置pytorch环境
高校教室管理系统,主要的模块包括查看首页、个人中心、教师管理、学生管理、教室信息管理、教师申请管理、学生申请管理、课时表管理、教师取消预约管理、学生取消预约管理等功能。
半挂汽车列车横向稳定性控制研究:基于模糊PID与制动力矩分配的联合仿真分析在典型工况下的表现,半挂汽车列车在典型工况下的横向稳定性控制研究:基于模糊PID与制动力矩分配的联合仿真分析,半挂汽车列车4自由度6轴整车model,横向稳定性控制,在低附着系数路面,进行典型3个工况,角阶跃,双移线,方向盘转角。 采用算法:模糊PID,制动力矩分配,最优滑移率滑膜控制。 以上基于trucksim和simulink联合仿真,有对应 p-a-p-e-r参考 ,关键词: 1. 半挂汽车列车 2. 4自由度6轴整车model 3. 横向稳定性控制 4. 低附着系数路面 5. 典型工况(角阶跃、双移线、方向盘转角) 6. 模糊PID算法 7. 制动力矩分配 8. 最优滑移率滑膜控制 9. Trucksim和Simulink联合仿真 10. P-A-P-E-R参考; 用分号隔开上述关键词为:半挂汽车列车; 4自由度6轴整车model; 横向稳定性控制; 低附着系数路面; 典型工况; 模糊PID算法; 制动力矩分配; 最优滑移率滑膜控制; Trucksim和Simulink联合仿真; P-A-P-E-R参考
路径规划人工势场法及其改进算法Matlab代码实现,路径规划人工势场法及其改进算法Matlab代码实现,路径规划人工势场法以及改进人工势场法matlab代码,包含了 ,路径规划; 人工势场法; 改进人工势场法; MATLAB代码; 分隔词“;”。,基于Matlab的改进人工势场法路径规划算法研究
本文介绍了范德堡大学深脑刺激器(DBS)项目,该项目旨在开发和临床评估一个系统,以辅助从规划到编程的整个过程。DBS是一种高频刺激治疗,用于治疗运动障碍,如帕金森病。由于目标区域在现有成像技术中可见性差,因此DBS电极的植入和编程过程复杂且耗时。项目涉及使用计算机辅助手术技术,以及一个定制的微定位平台(StarFix),该平台允许在术前进行图像采集和目标规划,提高了手术的精确性和效率。此外,文章还讨论了系统架构和各个模块的功能,以及如何通过中央数据库和网络接口实现信息共享。
三菱FX3U步进电机FB块的应用:模块化程序实现电机换算,提高稳定性和移植性,三菱FX3U步进电机换算FB块:模块化编程实现电机控制的高效性与稳定性提升,三菱FX3U 步进电机算FB块 FB块的使用可以使程序模块化简单化,进而提高了程序的稳定性和可移植性。 此例中使用FB块,可以实现步进电机的算,已知距离求得脉冲数,已知速度可以求得频率。 程序中包含有FB和ST内容;移植方便,在其他程序中可以直接添加已写好的FB块。 ,三菱FX3U;步进电机换算;FB块;程序模块化;稳定性;可移植性;距离与脉冲数换算;速度与频率换算;FB和ST内容;移植方便。,三菱FX3U步进电机换算FB块:程序模块化与高稳定性实现
光伏逆变器TMS320F28335设计方案:Boost升压与单相全桥逆变,PWM与SPWM控制,MPPT恒压跟踪法实现,基于TMS320F28335DSP的光伏逆变器设计方案:Boost升压与单相全桥逆变电路实现及MPPT技术解析,光伏逆变器设计方案TMS320F28335-176资料 PCB 原理图 源代码 1. 本设计DC-DC采用Boost升压,DCAC采用单相全桥逆变电路结构。 2. 以TI公司的浮点数字信号控制器TMS320F28335DSP为控制电路核心,采用规则采样法和DSP片内ePWM模块功能实现PWM和SPWM波。 3. PV最大功率点跟踪(MPPT)采用了恒压跟踪法(CVT法)来实现,并用软件锁相环进行系统的同频、同相控制,控制灵活简单。 4.资料包含: 原理图,PCB(Protel或者AD打开),源程序代码(CCS打开),BOM清单,参考资料 ,核心关键词:TMS320F28335-176; 光伏逆变器; 升压; 逆变电路; 数字信号控制器; 规则采样法; ePWM模块; PWM; SPWM波; MPPT; 恒压跟踪法; 原理图; PCB; 源程序代码; BOM
centos9内核安装包
昆仑通态触摸屏与两台台达VFD-M变频器通讯实现:频率设定、启停控制与状态指示功能接线及设置说明,昆仑通态TPC7062KD触摸屏与两台台达VFD-M变频器通讯程序:实现频率设定、启停控制与状态指示,昆仑通态MCGS与2台台达VFD-M变频器通讯程序实现昆仑通态触摸屏与2台台达VFD-M变频器通讯,程序稳定可靠 器件:昆仑通态TPC7062KD触摸屏,2台台达VFD-M变频器,附送接线说明和设置说明 功能:实现频率设定,启停控制,实际频率读取等,状态指示 ,昆仑通态MCGS; 台达VFD-M变频器; 通讯程序; 稳定可靠; 频率设定; 启停控制; 实际频率读取; 状态指示; 接线说明; 设置说明,昆仑通态MCGS与台达VFD-M变频器通讯程序:稳定可靠,双机控制全实现
研控步进电机驱动器方案验证通过,核心技术成熟可生产,咨询优惠价格!硬件原理图与PCB源代码全包括。,研控步进电机驱动器方案验证通过,核心技术掌握,生产准备,咨询实际价格,包含硬件原理图及PCB源代码。,研控步进电机驱动器方案 验证可用,可以生产,欢迎咨询实际价格,快速掌握核心技术。 包括硬件原理图 PCB源代码 ,研控步进电机驱动器方案; 验证可用; 可生产; 核心技术; 硬件原理图; PCB源代码,研控步进电机驱动器方案验证通过,现可生产供应,快速掌握核心技术,附硬件原理图及PCB源代码。
高质量的OPCClient_UA源码分享:基于C#的OPC客户端开发源码集(测试稳定、多行业应用实例、VS编辑器支持),高质量OPC客户端源码解析:OPCClient_UA C#开发,适用于VS2019及多行业现场应用源码分享,OPCClient_UA源码OPC客户端源码(c#开发) 另外有opcserver,opcclient的da,ua版本的见其他链接。 本项目为VS2019开发,可用VS其他版本的编辑器打开项目。 已应用到多个行业的几百个应用现场,长时间运行稳定,可靠。 本项目中提供测试OPCClient的软件开发源码,有详细的注释,二次开发清晰明了。 ,OPCClient_UA; OPC客户端源码; C#开发; VS2019项目; 稳定可靠; 详细注释; 二次开发,OPC客户端源码:稳定可靠的C#开发实现,含详细注释支持二次开发
毕业设计