試試下面的SQL語句是否符合你的需求: --A:
網(wǎng)站建設(shè)哪家好,找創(chuàng)新互聯(lián)公司!專注于網(wǎng)頁設(shè)計、網(wǎng)站建設(shè)、微信開發(fā)、成都小程序開發(fā)、集團企業(yè)網(wǎng)站建設(shè)等服務(wù)項目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了甘谷免費建站歡迎大家使用!
select XX_id
from tiantiantian
where sum_date=20110420
and XX_status 30
and XX_type in (1009, 1008, 1003, 1011)
and XX_date to_date(20110420, 'yyyymmdd')
and not exists(
select xx_id from dididi
where sum_date=20110420
and XX_status 30
and XX_type in (1009, 1008, 1003, 1011)
and XX_date to_date(20110420, 'yyyymmdd'));
--B:
select XX_id
from dididi
where sum_date=20110420
and XX_status 30
and XX_type in (2001)
and XX_date to_date(20110420, 'yyyymmdd')
and not exists(
select xx_id from tiantiantian
where sum_date=20110420
and XX_status 30
and XX_type in (2001)
and XX_date to_date(20110420, 'yyyymmdd'));
1。用rowid方法
據(jù)據(jù)oracle帶的rowid屬性,進行判斷,是否存在重復(fù),語句如下:
查數(shù)據(jù):
select * from table1 a where rowid
!=(select max(rowid)
from table1 b where a.name1=b.name1 and
a.name2=b.name2......)
刪數(shù)據(jù):
delete from table1 a where rowid
!=(select max(rowid)
from table1 b where a.name1=b.name1 and
a.name2=b.name2......)
2.group by方法
查數(shù)據(jù):
select count(num), max(name) from student --列出重復(fù)的記錄數(shù),并列出他的name屬性
group by num
having count(num) 1 --按num分組后找出表中num列重復(fù),即出現(xiàn)次數(shù)大于一次
刪數(shù)據(jù):
delete from student
group by num
having count(num) 1
這樣的話就把所有重復(fù)的都刪除了。
3.用distinct方法 -對于小的表比較有用
create table table_new as select distinct *
from table1 minux
truncate table table1;
insert into table1 select * from table_new;
SELECT DISTINCT TA.QA_TYPE TYPE,
TQ.TYPE_DESCRIPTION TYPEDESCRIPTION
FROM T_QA_RULE_DEFINE TA, T_QA_CHECK TQ
WHERE TA.QA_TYPE = TQ.TYPE
AND TA.QA_CHECK_TYPE = TQ.CHECK_TYPE
AND TA.VALID_FLAG = 'Y'
只取這兩個字段不就行了么,是不是你想要的
加distinct,
SELECT distinct sequence_no, channel_id, base_id, product_mode,model_code,rated_voltage, spec, brand_name, show_flag, model_id
FROM table_name
where user_id=1
查出來是沒有重復(fù)記錄的,如果想要model_id 沒有重復(fù),還需要做別的條件的限制