IT
实验室写程序发现的一些SQL技巧总结一下:

1.select count(*) as Num,supplier_city from supplier

where supplier_city is not null group by supplier_city order by Num desc

按城市数目多少统计

2.select company_street from company where len(company_street)>45 or len(company_street)<6

select company_city_name from company

where len(company_city_name)>24 or len(company_city_name)<5

根据长度判断城市和街道是否有效

3.删除重复的记录

select distinct NAME ,HOME into #Tmp from Test

drop table Test

select NAME ,HOME into Test from #Tmp

drop table #Tmp

4.联合查询

delete from company where company_id in

(select company_id from exhibition_company_relation where exhibition_id = '135331')

posted on 2009-07-14 15:47  liufei  阅读(166)  评论(0编辑  收藏  举报