【发布时间】:2017-04-12 06:56:24
【问题描述】:
我在数据库中有这些数据,看起来或多或少像这样:
id (int) not null unique | measurement_id (int) not null | range_id (int) not null unique | temperature (int) | TimeOfDay (string) either Dawn or Day or Night | Weather.Clear (Boolean) either true or null | Weather.Cloudy (Boolean) either true or null | Weather.Fog (Boolean) either true or null | Weather.Snow (Boolean) either true or null | Area.City (Boolean) either true ot null | Area.Country (Boolean) either true or null | etc
有数十万行,假设有人对这些数据进行了统计,例如 40% 的行在(TimeOfDay(字符串)Dawn 或 Day 或 Night)列中有 Day,65% 是在 (Weather.Clear (Boolean) true 或 null) 列等中为 true。此外,通常的逻辑适用,因此如果 Weather.Clear 设置为 true,则 Weather.Cloudy 为 null 等。
我的工作是找到“代表”组,比如说 1000 行数据。因此,我需要 1000 = 400 行中的 40% 在 (TimeOfDay (string) Dawn 或 Day or Night) 列中具有 Day,其中 65% (650) 在 (Weather.Clear (Boolean) 中具有“真”或真或 null) 列等。
我意识到仅使用 SQL (oracle) 查询来实现非常困难(或者我可能错了),所以我应该在这里使用什么样的方法来使用像 python 这样的通用编程语言来获得我需要的结果?这有什么算法吗?
问候。
【问题讨论】:
-
为了便于理解简化您的场景。给出几行的样本数据和基于此的预期输出。
-
Oracle 没有
boolean数据类型,那么这些值是如何表示的呢? -
@Utsav 示例,以防它可以更好地理解问题:[示例数据][1] [1]:i.stack.imgur.com/Nfo9q.png 当然,静态是在如下列上完成的:
temperature |时间 |天气。清除 |天气。多云 |天气。雾 |天气.雪 |地区.城市 |地区.国家 -
你说“当然”,但这并没有什么当然,这不是一个普通的数据库表。大概是在ETL过程中没有太多转换就加载的文件。
标签: python sql oracle algorithm