geo.md 790 字节
Newer Older
M
Mars Liu 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14
# 数值计算

Points 表结构如下:

```mysql
create table points(
    id int primary key auto_increment,
    x float,
    y float
)
```

现在 Joe 想要求写一个查询,得到每个点的id和模。即 √(x^2+y^2) 。这个查询应该是:

M
Mars Liu 已提交
15 16
点击进入[MySQL实战练习环境](https://mydev.csdn.net/product/pod/new?image=cimg-centos7-skilltreemysql&connect=auto&create=auto&utm_source=skill)

M
Mars Liu 已提交
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
## 答案

```mysql
select id, sqrt(x^2 + y^2) from points;
```

## 选项

### A

```mysql
select sqrt(vx+vy) from (select x^2 as vx, y^2 as vy from points) as t;
```

### B

```mysql
select sqrt(vx + vy) from points where x^2 as vx, y^2 as vy ;
```

### C

```mysql
select id + sqrt(x^2 + y^2) from points;
```

### D

```mysql
select id || sqrt(x^2 + y^2) from points;
```