Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT * FROM table WHERE category IN (
- SELECT category FROM (
- SELECT category, COUNT(*) AS c2 FROM (
- SELECT category, completed, COUNT(*) AS c1 FROM table
- GROUP BY category, completed
- ) AS t1
- GROUP BY category
- HAVING COUNT(*) > 1
- ) AS t2
- )
- B No
- C Yes
- B No
- B Yes
- C No
- C Yes
- public void Test()
- {
- try
- {
- var fLayer = ArcMap.Document.Maps.get_Item(0).get_Layer(0) as IFeatureLayer;
- var categories = Categorize((ITable)fLayer.FeatureClass, "Category", "Completed");
- foreach (KeyValuePair<string, List<string>> kvp in categories)
- {
- if (kvp.Value.Count > 1)
- Debug.Print("Category {0} has {1} unique values", kvp.Key, kvp.Value.Count);
- }
- }
- catch (Exception ex)
- {
- Debug.Print(ex.Message);
- }
- }
- public Dictionary<string, List<string>> Categorize(ITable table, string categoryFld, string otherFld)
- {
- var outList = new Dictionary<string, List<string>>();
- IQueryFilter qf = new QueryFilter();
- qf.SubFields = String.Format("{0},{1}", categoryFld, otherFld);
- int idxCat = FindField(table,categoryFld);
- int idxOther = FindField(table,otherFld);
- ICursor cur = null;
- // **edited to release cursor in a finally block**
- try
- {
- cur = table.Search(qf, true);
- IRow row;
- while ((row = cur.NextRow()) != null)
- {
- string category = GetStrVal(row, idxCat);
- string other = GetStrVal(row, idxOther);
- if (!outList.ContainsKey(category))
- outList.Add(category, new List<string>());
- if (!outList[category].Contains(other))
- outList[category].Add(other);
- }
- }
- catch
- {
- throw;
- }
- finally
- {
- System.Runtime.InteropServices.Marshal.FinalReleaseComObject(cur);
- }
- return outList;
- }
- public static string GetStrVal(IRow row, int idx)
- {
- return row.get_Value(idx) is DBNull ? "<Null>" : row.get_Value(idx).ToString();
- }
- public static int FindField(ITable table, string fldName)
- {
- int idx = table.FindField(fldName);
- if(idx == -1)
- throw new Exception(String.Format("field {0} not found on table {1}",
- fldName,((IDataset)table).Name));
- return idx;
- }
Add Comment
Please, Sign In to add comment