当前位置: 动力学知识库 > 问答 > 编程问答 >

ms access - sql query return the rows without common attributes

问题描述:

I'm new with sql ans ms-access.

So, i have table tab1, with columns

id, decscription, number

i want to make a query that returns the id of the rows without common description and number.

The desirable output is this

I have tried

SELECT id

FROM tab1

GROUP BY id, description, Number HAVING COUNT(*)=1;

but returns logical error.

网友答案:

If you want to return rows that are unique, you can do:

select *
from tab1
where not exists (select 1
                  from tab1 as t
                  where tab1.description = t.description and tab1.number = t.number and
                        tab1.id <> t.id
                 );

You can also do this using aggregation. To get the id:

select max(id)
from tab1
group by description, number
having min(id) = max(id);
网友答案:
SELECT  id
FROM tab1
GROUP BY  description, Number HAVING COUNT(*)=1;
网友答案:

Your question isn't quite clear, perhaps:

SELECT 
    id, description, Count(*) As Number
FROM 
    tab1
GROUP BY
    id, description
分享给朋友:
您可能感兴趣的文章:
随机阅读: