查看: 934|回复: 4
|
[Oracle]请问如何在同一个table里找出相同的data?
[复制链接]
|
|
比如说:我的table里有名字,地址。。等等。同一各地址可能有两个人住。
为了省却邮费,我想一次过寄给同一各地址。所以,要怎样才能在一个table里找出相同的地址,
然后展现出住户的名字和地址。以一对为准。如少过两个则不需show出来。
注:我是用SQL*Plus.
谢谢。。 |
|
|
|
|
|
|
|
发表于 16-4-2005 08:47 AM
|
显示全部楼层
SQL DISTINCT * FROM TABLE ORDER BY ADDRESS GROUP BY ADDRESS |
|
|
|
|
|
|
|
楼主 |
发表于 16-4-2005 02:22 PM
|
显示全部楼层
白日梦 于 16-4-2005 08:47 AM 说 :
SQL DISTINCT * FROM TABLE ORDER BY ADDRESS GROUP BY ADDRESS
坛主,我试了你的方法还是不能!
SQL> select DISTINCT * from patient ORDER BY address GROUP BY address;
select DISTINCT * from patient ORDER BY address GROUP BY address
*
ERROR at line 1:
ORA-00933: SQL command not properly ended
它的题目是这样的:
The hospital has prepared a survey to be sent to each patient. To save postage they wish to identify pairs of patients who live at the same address.
Name Null? Type
----------------------------------------- -------- ------------------------
PATIENTID NOT NULL CHAR(4)
SURNAME NOT NULL VARCHAR2(15)
GIVENNAMES VARCHAR2(15)
ADDRESS VARCHAR2(40)
PHONE VARCHAR2(15)
DATEOFBIRTH DATE
GENDER CHAR(1)
可能是我的翻译的不对,请多多包涵!
[ Last edited by sun_kid on 16-4-2005 at 07:18 PM ] |
|
|
|
|
|
|
|
发表于 17-4-2005 12:12 AM
|
显示全部楼层
SELECT *
FROM PATIENT A
WHERE ADDRESS=(SELECT ADDRESS
FROM PATIENT
WHERE ADDRESS=A.ADDRESS
GROUP BY ADDRESS
HAVING COUNT(*)>1) |
|
|
|
|
|
|
|
楼主 |
发表于 18-4-2005 05:45 PM
|
显示全部楼层
谢谢白日梦坛主和dino5100的解答。谢谢,谢谢 |
|
|
|
|
|
|
| |
本周最热论坛帖子
|