distinct

Oracle-洛总脚本--查询相关慢SQL

只愿长相守 提交于 2020-01-13 22:32:14
1、抓出外键没有创建索引的表(不依赖统计信息) with cons as (select /*+ materialize */ owner,table_name,constraint_name from dba_constraints where owner='SCOTT' and constraint_type='R'), idx as (select /*+ materialize */ table_owner,table_name,column_name from dba_ind_columns where table_owner='SCOTT') select owner,table_name,constraint_name,column_name from dba_cons_columns where (owner,table_name,constraint_name) in (select * from cons) and (owner,table_name,column_name) not in (select * from idx); 2、抓出需要收集直方图的列(依赖统计信息) select a.owner,a.table_name,a.column_name,b.num_rows,a.num_distinct cardinality, round(a.num

SQL Server select distinct hell

安稳与你 提交于 2020-01-13 20:30:10
问题 I'm stuck on a problem with sql. I have a table with many duplicate entries with column names like:- eventnumber housenumber value1 value2 None of these column names are the primary key as there are many duplicates. What I would like to do is select into another table by distinct housenumber but I seem to get the whole table copied across, I'm using:- Select * into temp_table from schedule_temp where housenumber in (select distinct housenumerb from schedule_temp) Now I broke it down a bit and

SQL Server select distinct hell

梦想的初衷 提交于 2020-01-13 20:29:27
问题 I'm stuck on a problem with sql. I have a table with many duplicate entries with column names like:- eventnumber housenumber value1 value2 None of these column names are the primary key as there are many duplicates. What I would like to do is select into another table by distinct housenumber but I seem to get the whole table copied across, I'm using:- Select * into temp_table from schedule_temp where housenumber in (select distinct housenumerb from schedule_temp) Now I broke it down a bit and

Swift 3 - NSFetchRequest Distinct Results

柔情痞子 提交于 2020-01-13 08:17:03
问题 Any help appreciated. Xcode auto updated to 8... I am Targeting IOS 9.3 Have all of the code converted across but one thing is now breaking, I have tried various suggestions in similar questions! My fetch request that was previously working is now breaking. My goal is to get a distinct list. The app crashes on the line: let results = try context.fetch(fetchRequest) With the error described in the console as: Could not cast value of type 'NSKnownKeysDictionary1' (0x10fd29328) to 'MyApp

Swift 3 - NSFetchRequest Distinct Results

♀尐吖头ヾ 提交于 2020-01-13 08:16:52
问题 Any help appreciated. Xcode auto updated to 8... I am Targeting IOS 9.3 Have all of the code converted across but one thing is now breaking, I have tried various suggestions in similar questions! My fetch request that was previously working is now breaking. My goal is to get a distinct list. The app crashes on the line: let results = try context.fetch(fetchRequest) With the error described in the console as: Could not cast value of type 'NSKnownKeysDictionary1' (0x10fd29328) to 'MyApp

数据库数据查询汇总

一个人想着一个人 提交于 2020-01-12 01:13:58
前言 数据查询 单表查询 连接查询 自身连接 内连接 外连接 多表连接 嵌套查询 集合查询 数据更新 插入数据 修改数据 删除数据 项目需求 前言 本篇博文主要是数据库SQL语句的总结,其中会有一些经常会忽略的小知识点。这里总结了数据查询和数据更新,其中比较重要且有难度的是连接查询和嵌套查询。最后列出了我在项目中所遇到的问题,但是SQL语句并没有做多少优化。主要是想拿出来做个笔记,同时供大家学习和交流,若是有优化的更好的SQL语句,可以在评论区给出。 数据查询 数据查询是数据库的核心操作。SQL提供了SELECT语句进行数据查询,该语句具有灵活的使用方式和丰富的功能。其一般格式为: SELECT [ALL|DISTINCT] <目标列表达式>[,<目标列表达式>]... FROM <表名或视图名> [,<表名或视图名>...]|(<SELECT语句>)[AS]<别名> [WHERE <条件表达式>] [GROUP BY <列名1> [HAVING <条件表达式>]] [ORDER BY <列名2> [ASC|DESC]]; 整个SELECT语句的含义是,根据WHERE子句的条件表达式从FROM子句指定的基本表、视图或派生表中找出满足条件的元组,再按SELECT子句中的目标列表达式选出元组中的属性值形成结果表。如果有GROUP BY子句,则将结果按<列名1>的均值进行分组

SQL query returning “Operand should contain 1 column(s)”

守給你的承諾、 提交于 2020-01-11 12:48:27
问题 I'm currently working on a query which will have all rows from one table, but only limited information from the other. I've tried working with this query: SELECT `t`.`uid`, `t`.`cid`, `t`.`id` FROM `tracking` as `t` JOIN (SELECT DISTINCT(`p`.`id`, `p`.`firstname`, `p`.`lastname`, `p`.`company`) FROM `publishers` as `p`) as `p` ON `p`.id = `t`.uid However, I get the error as in the topic heading. Can anyone see what I'm doing wrong here? Edit: Structure on tracking: id int(11) primary ai, cid

SQL CE DISTINCT AGGREGATE

旧城冷巷雨未停 提交于 2020-01-11 12:04:13
问题 Does SQL CE has the ability to use distinct in aggregate functions? I need something like SELECT count(distinct date) FROM table This is simplified query and I already have GROUP BY used in original one. 回答1: SQL Server CE (current version) does not support count(distinct) The workaround is a GROUP BY, which sounds like what you are using select count(*) from ( select distinct date from tbl ) x Or if other fields are involved select groupcol, count(*) from ( select groupcol, date from tbl

Count Distinct over partition by sql

半腔热情 提交于 2020-01-11 10:34:49
问题 I have a table like col1ID col2String Col3ID Col4String Col5Data 1 xxx 20 abc 14-09-2018 1 xxx 20 xyz 14-09-2018 2 xxx 30 abc 14-09-2018 2 xxx 30 abc 14-09-2018 I would like to add column which count how many different strings I have in col4String group by col1ID and col3ID. So something like COUNT(DISTINCT (Col4String)) over (partition by col1ID, col3ID) but it doesn't work, I receive an error Use of DISTINCT is not allowed with the OVER clause. Msg 102, Level 15, State 1, Line 23. I have