查看: 1082|回复: 5
|
如何在oracle database 跑SQL 用两個 dependent where condition?
[复制链接]
|
|
請問有誰知道最簡单的sql query 显示出我要的result.
select field_1, field_2
from table_a
where field_1 in ('A','B','C')
or field_2 in ('1','2','3')
我要的答案是
field_1 field_2
A 1
B 2
C 3
我不要
A 2
A 3
B 1
B 3
C 1
C 2 |
|
|
|
|
|
|
|
发表于 25-8-2005 08:39 AM
|
显示全部楼层
select distinct field1,field2 from table_a group by field1,field2 |
|
|
|
|
|
|
|
发表于 26-8-2005 09:02 AM
|
显示全部楼层
select field_1, field_2
from table_a
where
(field_1='A' and field_2='1')
or (field_1='B' and field_2='2')
or (field_1='C' and field_2='3') |
|
|
|
|
|
|
|
发表于 29-8-2005 12:46 PM
|
显示全部楼层
原帖由 白日梦 于 25-8-2005 08:39 AM 发表
select distinct field1,field2 from table_a group by field1,field2
错!field1,field2已经够distinct了.
原帖由 C7 于 26-8-2005 09:02 AM 发表
select field_1, field_2
from table_a
where
(field_1='A' and field_2='1')
or (field_1='B' and field_2='2')
or (field_1='C' and field_2='3')
太HARDCODE了。
我觉得簡单的sql query应该做不到。 |
|
|
|
|
|
|
|
发表于 29-8-2005 01:02 PM
|
显示全部楼层
想知道你ABC,123在table_a里面的排法,是
Field1 Field2
A 1
B 2
C 3
还是
Field1 Field2
A
B
C
1
2
3
还是怎样的? |
|
|
|
|
|
|
|
发表于 4-9-2005 08:18 PM
|
显示全部楼层
select field_1, (select field_2 from table_a where field_2 in ('1','2','3'))
from table_a
where field_1 in ('A','B','C') |
|
|
|
|
|
|
| |
本周最热论坛帖子
|