distinct

Select distinct pairs joining a table to itself in sql

青春壹個敷衍的年華 提交于 2019-12-13 16:06:58
问题 I have a table with two rows: IMDB_ID and Actor. I am trying to find the pairs of actors who co-stared in 3 or more movies. The pairs of names should be unique, meaning that ‘actor A, actor B’ and ‘actor B, actor A’ are the same pair, so only one of them should appear. Here's a few lines of the table, but not the whole thing: IMDB_ID ACTOR ---------- ----------- tt0111161 Tim Robbins tt0111161 Morgan Free tt0111161 Bob Gunton tt0111161 William Sad tt0111161 Clancy Brow tt0111161 Gil Bellows

Getting a distinct value across 2 union sql server tables

烂漫一生 提交于 2019-12-13 12:24:49
问题 I'm trying to get all distinct values across 2 tables using a union. The idea is to get a count of all unique values in the columnA column without repeats so that I can get a summation of all columns that contain a unique columnA. This is what I tried (sql server express 2008) select count(Distinct ColumnA) from ( select Distinct ColumnA as ColumnA from tableX where x = y union select Distinct ColumnA as ColumnA from tableY where y=z ) 回答1: SELECT COUNT(distinct tmp.ColumnA) FROM ( (SELECT

Selecting distinct pair mysql

霸气de小男生 提交于 2019-12-13 12:07:06
问题 I would like to select the rows that has the same values across column A and column B. For example if my table is A B 1 2 3 4 1 2 4 5 The output should be A B 1 2 A. Select Distinct A,B from table selects all the values in the table. B. Select Distinct (A,B) from table tells me that Distinct function can take only one value. C. Select A,B from table group by A,B Selects all the values in the table (Similar to A). The question is similar to Selecting Distinct combinations. but the answer

Sprade distinct values over a different columns

不问归期 提交于 2019-12-13 09:07:45
问题 I'm using SQL Server. I have the following table ( MyTable ): ID (int) value (varchar) I have the following query: select distinct value from MyTable And the output is: Value_1 Value_2 Value_3 ... ... ... Value_450 I would like to crate the following table (when value = 'value_1' then 1 else o...): ID | Value_1 | Value_2 | Value_3 | Value_4 | .... | Value_450 1 | 0 | 1 | 0 | 0 | .... | 0 2 | 0 | 0 | 0 | 1 | .... | 0 3 | 1 | 0 | 0 | 0 | .... | 0 4 | 0 | 1 | 0 | 0 | .... | 0 5 | 0 | 0 | 0 | 0 |

Count distinct non-null rows in a datatable

痞子三分冷 提交于 2019-12-13 08:30:18
问题 I want to count the distinct values in a column of a datatable. I found this useful technique: count = dataTable.DefaultView.ToTable(true, "employeeid").rows.count This works fine if there are no nulls in the column, but if there are, the count is high by one. Is there a way to eliminate null valued rows from the count, or do I have to loop through the resulting table looking for a possible null? tbl = dataTable.DefaultView.ToTable(true,"employeeid") For Each row in tbl.rows ... 回答1: You may

GROUP_BY WITH DISTINCT QUERY

旧时模样 提交于 2019-12-13 07:59:07
问题 Am using Oracle 12c, below is the column: CENTER_ID UNIT EMPLOYEEID LESSON MINS_STUDIED SECTION I234 4 G01234 4.1 5 EX I234 4 G01234 4.1 5 LN I234 4 G01234 4.1 5 VO I234 4 G0123 4.2 5 EX I234 4 G0123 4.2 5 LN I234 4 G0123 4.2 5 VO I2345 5 G023 5.2 12 EX I2345 5 G023 5.2 12 LN I2345 5 G023 5.2 12 VO From record 1 to 6, it contains 2 distinct employee_id who studied unit 4. In this case, I need total minutes spent per unit (center_id wise). But I want to add only distinct MINS_STUDIED based on

Total sum wrong value in Dynamic Pivot

牧云@^-^@ 提交于 2019-12-13 07:49:11
问题 I have complicated query which works pretty good (MS SQL 2012). But it makes a mistake when sum up same price items. It count them correctly but only takes price once instead of taking them as a count number. It only appears when same item has same price and from same country. Here is my query ; CREATE TABLE #ITEMS(ID INT,NAME VARCHAR(30)) INSERT INTO #ITEMS SELECT 1, 'laptop' UNION ALL SELECT 2, 'phone' UNION ALL SELECT 3, 'playstation' UNION ALL SELECT 4, 'MacBook' CREATE TABLE #Country(ID

Find all distinct values in user based selection - Excel VBA

不问归期 提交于 2019-12-13 06:24:12
问题 is there a quick and easy way to select all distinct values within a given selection in Excel with VBA? 0 | we | 0 --+----+-- we| 0 | 1 -> the result should be {0,we,1} Many thanks in advance 回答1: Give this a try: Sub Distinct() Dim c As Collection Set c = New Collection Dim r As Range Dim dis As Range Set dis = Nothing For Each r In Selection If r.Value <> "" Then On Error Resume Next c.Add r.Value, CStr(r.Value) If Err.Number = 0 Then If dis Is Nothing Then Set dis = r Else Set dis = Union

Creating SharePoint View with Distinct Column value

99封情书 提交于 2019-12-13 04:41:18
问题 Is it possible to create a custom list view (Not a list view webpart) with unique column value. I have one list which has 5 column like project ID, Project Name, Activity ID, Status, Points. I want to create a Custom list view where the Activity ID column should be return distinct value only. How Can I achieve this goal? Please help to do this. All suggestions and answers will be appreciated. Thanks in advance.. 回答1: SharePoint List views are based on CAML queries and CAML does not support

SQL count and distinct query

瘦欲@ 提交于 2019-12-13 04:26:25
问题 I'm trying to build up a query that would count and distinct at the same time. This is the raw data Raw Data +--------+---------+ | IntID | ErrorID | +--------+---------+ | ins001 | 1 | | ins001 | 1 | | ins001 | 2 | | ins002 | 3 | | ins002 | 5 | | ins002 | 5 | | ins003 | 4 | | ins003 | 1 | | ins003 | 1 | +--------+---------+ What im trying to accomplish is a count for each error id for each distinct instrument id, as shown below: What is expected +--------+-------------+-------------+--------