资源描述:
《sql_server2000知识点全集1》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、mysql查询语句全集--列出pet所有的列select*frompet--列出指定的列selectname,ownerformpet--直接进行算术运算,对字段起别名selectsin(1+2)assin--where条件select*frompetwhere(birth>'1980'andspecies='dog')orspecies='bird'--对null的条件select*frompetwheresexisnotnull--所有名字第四位是n的宠物信息是select*frompetwhereown
2、erlike'___n%'--所有主人名叫gwen或benny的宠物select*frompetwhereownerin('gwen','benny')--查询出生日期在90年代是宠物,相当与>=and<=select*frompetwherebirthbetween'1990'and'1999'--按主人姓名排序,相同的按宠物姓名倒序排列select*frompetorderbyowner,namedesc--查询性别为公的宠物,按生日倒序排列select*frompetwheresex='m'orderb
3、ybirthdesc--char_lenngth()返回的字符的长度,length()返回字节长度SELECTowner,length(owner),char_length(owner)FROMpetp;--列出养有宠物狗的人名selectdistinctownerfrompetwherespecies='dog'--用两种方法查询出所有狗和猫的名字、出生年份、出生月份selectname,left(birth,4)asyear,mid(birth,6,2)asmonthfrompetwherespecies
4、='dog'orspecies='cat'selectname,year(birth)asyear,month(birth)asmonthfrompetwherespeciesin('dog','cat')--查询所有名字中存在字母'e'的人,将他们养的宠物按类别、年龄排序selectname,species,birthfrompetwhereownerlike'%e%'orderbyspecies,birthdesc--数字函数selectround(2.345,2),truncate(2.345,2),m
5、od(323,5)--日期函数selectnow(),curdate(),curtime()selectadddate('2007-02-02',interval31day)--求出所有宠物的年龄selectname,birth,truncate(datediff(now(),birth)/365,0)asage1,year(now())-year(birth)-(dayofyear(birth)>dayofyear(now()))asage2frompet--分组函数selectmin(birth),max
6、(birth),avg(birth),count(*),count(sex),sum(birth)frompet--每种宠物各有几只selectspecies,count(*)frompetgroupbyspecies--查询年龄最大的宠物的信息select*frompetwherebirth=(selectmax(birth)frompet)--每年各出生了几只宠物selectyear(birth),count(*)frompetgroupbyyear(birth)--鸟和猫的性别比例selectspeci
7、es,sex,count(*)frompetwherespeciesin('cat','bird')groupbyspecies,sex--各种宠物年龄的和selectspecies,sum(truncate(datediff(now(),birth)/365,0))asSumAgefrompetgroupbyspecies--数量大于1的宠物种类selectspecies,count(*)ascfrompetgroupbyspecieshavingc>=2--基本双表关联selecta.name,a.spe
8、cies,a.sex,b.date,b.type,b.remarkfrompeta,eventbwherea.name=b.name--查询宠物产仔时的年龄selecta.name,a.species,truncate(datediff(b.date,a.birth)/365,0)asagefrompeta,eventbwherea.name=b.nameandb.type='litter'--90