小编Pat*_*len的帖子

在SQL中查找连续增加的数字的最长序列

对于这个例子,我说我有一个包含两个字段的表,AREA varchar(30)OrderNumber INT.

该表具有以下数据

AREA      | OrderNumber
Fontana   |       32
Fontana   |       42
Fontana   |       76
Fontana   |       12
Fontana   |        3
Fontana   |       99
RC        |       32
RC        |        1
RC        |        8
RC        |        9
RC        |        4
Run Code Online (Sandbox Code Playgroud)

我想回来

我想要返回的结果是每个区域增加连续值的最长长度.为了Fontana it is 3 (32, 42, 76).For RC it is 2 (8,9)

AREA    | LongestLength
Fontana |          3
RC      |          2
Run Code Online (Sandbox Code Playgroud)

我如何在MS Sql 2005上执行此操作?

sql sql-server

5
推荐指数
1
解决办法
2416
查看次数

加入一个范围的最佳方式?

我认为这可能是一个常见的问题,可能无法解决每个工具.现在我们正在尝试使用amazons Redshift.我们现在唯一的问题是我们正在尝试查找IP地址的邮政编码.我们将IP连接到城市的表是IP转换为整数的范围.

例:

Start IP | End IP  | City

| 123123 | 123129 | Rancho Cucamonga|
Run Code Online (Sandbox Code Playgroud)

我在intip> = startip和intip <endip上尝试了明显的内连接.

有谁知道这样做的好方法?

sql postgresql range-types amazon-redshift

2
推荐指数
1
解决办法
3931
查看次数

如何将垂直数据透视到具有可变行长度的水平数据SQL?

好的,我有下表.

Name    ID  Website

Aaron | 2305 |  CoolSave1


Aaron | 8464 |  DiscoWorld1


Adriana |   2956 |  NewCin1


Adriana |   5991 |  NewCin2


Adriana | 4563  NewCin3
Run Code Online (Sandbox Code Playgroud)

我想将其转换为以下方式.

Adriana  |  2956 |  NewCin1 |   5991 |  NewCin2 | 4563  | NewCin3


Aaron | 2305 | CoolSave1 |  8464 |  DiscoWorld | NULL | NULL    
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,我正在尝试从第一个表中获取名字,并使用与该名称关联的所有ID /网站创建一行.问题是,有可变数量的网站可能与每个名称相关联.为了解决这个问题,我想制作一个表格,其中字段数等于最大行项目,然后对于后续的行项目,插入一个没有足够数据的NULL.

sql pivot sql-server-2005 unpivot

0
推荐指数
1
解决办法
2360
查看次数

有没有办法在猪中添加日期时间?

what I would like to do in pig is something that is very common in sql. I have date field that is of the form yyy-mm-dd hh:mm:ss and I have another field that contains an integer which represents an amount of hours. Is there a way to easily add the integer to the datetime field so that we get a result of what we expect with clock math.

Example: date is 2013-06-01 : 23:12:12.

Then I add 2 hours

I …

hadoop apache-pig

0
推荐指数
1
解决办法
2852
查看次数