我需要一个像这样的SELECT * FROM表1的Mysql查询,其中列值= 1,2或3并且在外部下是唯一的(在一个外键列值下面= 1应该只有一个条目)找到重复值的计数在外键下
答案 0 :(得分: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
答案 1 :(得分:0)
SELECT COUNT(*) FROM dbo.Table1 WHERE [ColumnName] = 'abc' OR [ColumnName] = 'def' OR [ColumnName] = 'ghi' HAVING COUNT(*) > 1
答案 2 :(得分:0)
SELECT colValue, count(colValue) as cnt
FROM table1
where colValue in (1,2,3)
group by colValue
having cnt>1
答案 3 :(得分: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