0

我需要这样的 Mysql 查询 SELECT * FROM table 1 where column value = 1,2 or 3 and unique under a foreign (在一个外键下,colum value =1 应该只有一个条目) 找到外来重复值的计数钥匙

4

4 回答 4

0

尝试这个:

SELECT
    <Table1>.id, COUNT(<Table1>.Id) 
FROM <Table1>
INNER JOIN <Table2> ON <Table1>.Id = <Table2>.Id
GROUP BY id
HAVING COUNT(<Table1>.Id) > 1
于 2013-07-30T06:20:33.073 回答
0
SELECT COUNT(*) FROM dbo.Table1 WHERE [ColumnName] = 'abc' OR [ColumnName] = 'def' OR [ColumnName] = 'ghi' HAVING COUNT(*) > 1
于 2013-07-30T06:21:56.357 回答
0
SELECT colValue, count(colValue) as cnt  
FROM table1
where colValue in (1,2,3)
group by colValue 
having cnt>1
于 2013-07-30T06:24:07.860 回答
0

试试这个,它只给出唯一的值。

SELECT *
  FROM TABLE t
  JOIN (SELECT *,
               ROW_NUMBER() OVER (PARTITION BY foreignkey_Col ORDER BY id) as rno
       FROM TABLE c
       ) ta ON ta.id = t.id
  AND ta.rno=1
于 2013-07-30T06:30:36.227 回答