阿里云瑶池数据库SQL挑战令题目三

简介: 阿里云瑶池数据库SQL挑战令题目三
题目:

该表的每一行包含一个点的三维坐标,写一个sql查询,计算每个三角形的面积,保留两位小数。

解题思路:

首先需要知道关于三维坐标的三角形面积的求解公式,然后才能进行计算,否则的话就没有办法进行计算处理:

DM的处理

计提思路:

第一步、先进行行转列的处理

select t.id,

(select p.x from Point p where  t.`pointId1` =p.id) as px1,

(select p.y from Point p where  t.`pointId1` =p.id) as py1,

(select p.z from Point p where  t.`pointId1` =p.id) as pz1,

(select p.x from Point p where  t.`pointId2` =p.id) as px2,

(select p.y from Point p where  t.`pointId2` =p.id) as py2,

(select p.z from Point p where  t.`pointId2` =p.id) as pz2,

(select p.x from Point p where  t.`pointId3` =p.id) as px3,

(select p.y from Point p where  t.`pointId3` =p.id) as py3,

(select p.z from Point p where  t.`pointId3` =p.id) as pz3

from `triangle`  t   where  t.id=1

第二步,代入公式计算是否正确:

select id as TriangleId ,round(((px2-px1)*(px3-px1)*(py2-py1)*(py3-py1)*(pz2-pz1)*(pz3-pz1))/2,2) as Area from (

select t.id,

(select p.x from Point p where  t.`pointId1` =p.id) as px1,

(select p.y from Point p where  t.`pointId1` =p.id) as py1,

(select p.z from Point p where  t.`pointId1` =p.id) as pz1,

(select p.x from Point p where  t.`pointId2` =p.id) as px2,

(select p.y from Point p where  t.`pointId2` =p.id) as py2,

(select p.z from Point p where  t.`pointId2` =p.id) as pz2,

(select p.x from Point p where  t.`pointId3` =p.id) as px3,

(select p.y from Point p where  t.`pointId3` =p.id) as py3,

(select p.z from Point p where  t.`pointId3` =p.id) as pz3

from `triangle`  t  )  tt

相关文章
|
存储 NoSQL Redis
阿里云高性能数据库Tair(兼容 Redis)收费价格,稳定可靠成本低
阿里云高性能云数据库Tair兼容Redis,提供Redis开源版和Tair企业版,支持多种存储介质与灵活扩展,适用于高并发场景。Tair具备亚毫秒级稳定延迟,保障业务连续性。价格方面,Redis开源版年费从72元起,Tair企业版年费从1224元起,具体费用根据配置不同有所变化。
|
关系型数据库 MySQL 数据库
阿里云数据库RDS费用价格:MySQL、SQL Server、PostgreSQL和MariaDB引擎收费标准
阿里云RDS数据库支持MySQL、SQL Server、PostgreSQL、MariaDB,多种引擎优惠上线!MySQL倚天版88元/年,SQL Server 2核4G仅299元/年,PostgreSQL 227元/年起。高可用、可弹性伸缩,安全稳定。详情见官网活动页。
2106 152
|
关系型数据库 MySQL 数据库
阿里云数据库RDS支持MySQL、SQL Server、PostgreSQL和MariaDB引擎
阿里云数据库RDS支持MySQL、SQL Server、PostgreSQL和MariaDB引擎,提供高性价比、稳定安全的云数据库服务,适用于多种行业与业务场景。
1439 156
|
关系型数据库 MySQL 分布式数据库
阿里云PolarDB云原生数据库收费价格:MySQL和PostgreSQL详细介绍
阿里云PolarDB兼容MySQL、PostgreSQL及Oracle语法,支持集中式与分布式架构。标准版2核4G年费1116元起,企业版最高性能达4核16G,支持HTAP与多级高可用,广泛应用于金融、政务、互联网等领域,TCO成本降低50%。
|
关系型数据库 MySQL 网络安全
5-10Can't connect to MySQL server on 'sh-cynosl-grp-fcs50xoa.sql.tencentcdb.com' (110)")
5-10Can't connect to MySQL server on 'sh-cynosl-grp-fcs50xoa.sql.tencentcdb.com' (110)")
|
SQL 存储 监控
SQL Server的并行实施如何优化?
【7月更文挑战第23天】SQL Server的并行实施如何优化?
1140 13
解锁 SQL Server 2022的时间序列数据功能
【7月更文挑战第14天】要解锁SQL Server 2022的时间序列数据功能,可使用`generate_series`函数生成整数序列,例如:`SELECT value FROM generate_series(1, 10)。此外,`date_bucket`函数能按指定间隔(如周)对日期时间值分组,这些工具结合窗口函数和其他时间日期函数,能高效处理和分析时间序列数据。更多信息请参考官方文档和技术资料。
904 9
|
SQL 存储 网络安全
关系数据库SQLserver 安装 SQL Server
【7月更文挑战第26天】
537 6