Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

²»´íµÄSQLÃæÊÔÌ⣨һ£©

Student(S#,Sname,Sage,Ssex) ѧÉú±í
Course(C#,Cname,T#) ¿Î³Ì±í
SC(S#,C#,score) ³É¼¨±í
Teacher(T#,Tname) ½Ìʦ±í
ÎÊÌ⣺
1¡¢²éѯ“001”¿Î³Ì±È“002”¿Î³Ì³É¼¨¸ßµÄËùÓÐѧÉúµÄѧºÅ£»
  select a.S# from (select s#,score from SC where C#='001') a,(select s#,score
  from SC where C#='002') b
  where a.score>b.score and a.s#=b.s#;
2¡¢²éѯƽ¾ù³É¼¨´óÓÚ60·ÖµÄͬѧµÄѧºÅºÍƽ¾ù³É¼¨£»
    select S#,avg(score)
    from sc
    group by S# having avg(score) >60;
3¡¢²éѯËùÓÐͬѧµÄѧºÅ¡¢ÐÕÃû¡¢Ñ¡¿ÎÊý¡¢×ܳɼ¨£»
  select Student.S#,Student.Sname,count(SC.C#),sum(score)
  from Student left Outer join SC on Student.S#=SC.S#
  group by Student.S#,Sname
4¡¢²éѯÐÕ“ÀÄÀÏʦµÄ¸öÊý£»
  select count(distinct(Tname))
  from Teacher
  where Tname like 'Àî%';
5¡¢²éѯûѧ¹ý“Ҷƽ”ÀÏʦ¿ÎµÄͬѧµÄѧºÅ¡¢ÐÕÃû£»
    select Student.S#,Student.Sname
    from Student 
    where S# not in (select distinct( SC.S#) from SC,Course,Teacher where  SC.C#=Course.C# and Teacher.T#=Course.T# and Teacher.Tname='Ҷƽ');
6¡¢²éѯѧ¹ý“001”²¢ÇÒҲѧ¹ý±àºÅ“002”¿Î³ÌµÄͬѧµÄѧºÅ¡¢ÐÕÃû£»
  select Student.S#,Student.Sname from Student,SC where Student.S#=SC.S# and SC.C#='001'and exists( Select * from SC as SC_2 where SC_2.S#=SC.S# and SC_2.C#='002');
7¡¢²éѯѧ¹ý“Ҷƽ”ÀÏʦËù½ÌµÄËùÓпεÄͬѧµÄѧºÅ¡¢ÐÕÃû£»
  select S#,Sname
  from Student
  where S# in (select S# from SC ,Course ,Teacher where SC.C#=Course.C# and Teacher.T#=Course.T# and Teacher.Tname='Ҷƽ' group by S# having count(SC.C#)=(select count(C#) from Course,Teacher  where Teacher.T#=Course.T# and Tname='Ҷƽ'));
8¡¢²éѯ¿Î³Ì±àºÅ“002”µÄ³É¼¨±È¿Î³Ì±àºÅ“001”¿Î³ÌµÍµÄËùÓÐͬѧµÄѧºÅ¡¢ÐÕÃû£»
  Select S#,Sname from (select Student.S#,Student.Snam


Ïà¹ØÎĵµ£º

SQL distinctÓ÷¨¡¡¼òµ¥group by ÃüÁî


distinctÕâ¸ö¹Ø¼ü×ÖÓÃÀ´¹ýÂ˵ô¶àÓàµÄÖظ´¼Ç¼ֻ±£ÁôÒ»Ìõ£¬µ«ÍùÍùÖ»ÓÃËüÀ´·µ»Ø²»Öظ´¼Ç¼µÄÌõÊý£¬¶ø²»ÊÇÓÃËüÀ´·µ»Ø²»ÖؼǼµÄËùÓÐÖµ¡£ÆäÔ­ÒòÊÇdistinctÖ»ÓÐÓöþÖØÑ­»·²éѯÀ´½â¾ö£¬¶øÕâÑù¶ÔÓÚÒ»¸öÊý¾ÝÁ¿·Ç³£´óµÄÕ¾À´Ëµ£¬ÎÞÒÉÊÇ»áÖ±½ÓÓ°Ï쵽ЧÂʵġ£
ÏÂÃæÏÈÀ´¿´¿´Àý×Ó£º
table±í
×Ö¶Î1      ×Ö¶ ......

¹ØÓÚSql´æ´¢¹ý³Ì


SQL ÖеĴ洢¹ý³Ì£º
1.ÔÚ½¨Á¢´æ´¢¹ý³Ì֮ǰ¼ì²éËùÃüÃûµÄ´æ´¢¹ý³ÌÊÇ·ñÓ¦¾­´æÔÚ¡££¨ÒòΪÈç¹ûͬÃû´æ´¢¹ý³ÌÒѾ­´æÔÚ£¬ÐµĴ洢¹ý³Ì½«²»±»½¨Á¢£©
if exists(select * from sysobject where name='proc name' and type='p')
drop proc proc name
   go
2.¶¨Òå´æ´¢¹ý³Ì
create proc test
@gradel int, --¶¨Òå±äÁ ......

hibernate sql ²Ù×÷

@SuppressWarnings("unchecked")
    public List<ZxFunction> selectFunctionParentByUserId(final int userId) {
        try {
            final String sql = "select *  from zx_function ......

ÓÃSHELLµÄÑ­»·ÅúÁ¿Ö´ÐÐSQLÓï¾ä

--kshϵÄÒ»¸öWHILE Ñ­»·µÄÀý×Ó
integer i=1
while ((i<67))
do 
  pirnt $i
  i=i+1
done
--ksh ÏÂÒ»¸öFORÑ­»·µÄÀý×Ó
for i in `cat listdate.txt`
do
  echo "Ö´ÐÐ $i "
done
--- date.pl ÓÃÓÚÉú³ÉÒ»¸öʱ¼ä¶ÎÎļþ
#!/usr/local/bin/perl
use DBI;
if($#ARGV<1)
 {
&nbs ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ