0
id_detail_item id_item   id_detail_item_name
1              1         abc 
2              1         abcd
3              1         cde
4              3         zki
5              3         zkr

如何检查同一个“id_item”中的“id_detail_item_name”是否有两个不同的数据?

我尝试了以下方法,但出现错误:

SELECT id_item FROM table_detail_item WHERE id_detail_item_name='abc' AND id_detail_item_name='abcd';
4

3 回答 3

0

那是因为 AND 运算符意味着必须满足这两个条件。

尝试:

SELECT * FROM table_detail_item 
WHERE id_item = '1' 
AND id_detail_item_name IN ('abc', 'abcd');
于 2013-08-24T05:21:18.080 回答
0

这应该列出至少有两个不同id_detail_item_name的 所有条目id_item

SELECT id_item, MIN(id_detail_item_name) nam1,max(id_detail_item_name) nam2 
FROM table_detail_item 
GROUP by id_item HAVING MIN(id_detail_item_name) nam1<MAX(id_detail_item_name)
于 2013-08-24T05:22:38.763 回答
0

尝试

select id_item
  from (
              select min(id_detail_item_name) mmin
                   , max(id_detail_item_name) mmax
                from table_detail_item
            group by id_item
       ) agg
 where agg.mmin <> agg.mmax
     ;
于 2013-08-24T05:26:45.860 回答