SELECT DISTINCT 仅前四个数字 [英] SELECT DISTINCT only first four numbers

查看:39
本文介绍了SELECT DISTINCT 仅前四个数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑下表:

ticker  code
--------------
AA      151040
AAP     452020
DOW     151010
DVN     151020
EXC     452050
FAD     452070
POE     207010

我想选择每个代码的代码 - 但只需要对代码的前四个数字进行比较(例如:1510、4520、1510 等),结果如下:

I would like to select the tickers per code - but comparison has to be made on only the first four numbers of the code (so: 1510, 4520, 1510, etc), giving a result like:

1510 AA
1510 DOW
1510 DVN
4520 AAP
4520 EXC
4520 FAD
2070 POE

用什么查询可以只取前四个数字?

With what query can I take only the first four numbers?

推荐答案

使用 :

SELECT LEFT(code, 4) AS code, ticker FROM tbl ORDER BY code;

这篇关于SELECT DISTINCT 仅前四个数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆