复习之左右外连接

欢迎来到unity学习unity培训unity企业培训教育专区,这里有很多U3D资源U3D培训视频U3D教程U3D常见问题U3D项目源码,我们致力于打造业内unity3d培训、学习第一品牌。


今天讲了模糊查询,左、右外连接,以及在VS中多表连接

废话不多说,先上SQL语句


模糊查询


//查询姓名字段中有qq关键字的项

select name from users where name like '%qq%'


 //查询表中姓名和年龄字段里面年龄为空的项

select name,age from users where age is null


//查询表中姓名和年龄字段里面年龄不为空的项

select name,age from users where age is not null 


//查询表中姓名和年龄字段里面年龄在21到24之间的项

select name,age from users where age between 21 and 24

select name,age from users where age>=21 and age<=24


//查询表中姓名和年龄里面年龄是21,22,24的项

select name,age from users where age in(21,22,24)

//查询表中姓名和年龄里面年龄不是21,22,24的项

select name,age from users where age not in(21,22,24)


//求总年龄,平均年龄,最大年龄,最小年龄以及总人数

select sum(age) 总年龄 from users

select avg(age) 平均年龄 from users

select max(age) 最大年龄,min(age) 最小年龄 from users

select count(*) 总人数 from users

select id 编号,avg(age) 平均年龄 from users group by id

select name,avg(age) 平均年龄 from users group by name

select id,name,avg(age) 平均年龄 from users group by id, name


//左外连接

select u.name,c.amount,c.price from users as u left join cart as c on u.id=c.uid


//右外连接

select u.name,c.amount,c.price from users as u right join cart as c on u.id=c.uid


下面上代码~

  1. public int insertCart(int amount, decimal price,int uid,int eid)
  2.         {
  3.             SqlConnection con = DB.Connect();
  4.             con.Open();
  5.             string sql = "insert into cart values("+amount+","+price+","+uid+","+eid+")";
  6.             SqlCommand com = new SqlCommand(sql, con);
  7.             int i = com.ExecuteNonQuery();
  8.             return i;
  9.         }

  10.         public ArrayList select() {
  11.             SqlConnection con = DB.Connect();
  12.             con.Open();
  13.             string sql = "select u.name,e.name,c.amount,c.price from cart c "+
  14.                           "inner join users u on u.id=c.uid "+
  15.                           "inner join equip e on e.id=c.eid";
  16.             SqlCommand com = new SqlCommand(sql, con);
  17.             SqlDataReader reader = com.ExecuteReader();
  18.             while(reader.Read()){
  19.                 Users u = new Users();
  20.                 u.Name = (string)reader.GetValue(0);
  21.                 Equip e = new Equip();
  22.                 e.Name = (string)reader.GetValue(1);
  23.                 Cart c = new Cart();
  24.                 c.Amount =(int) reader.GetValue(2);
  25.                 c.Price =(decimal) reader.GetValue(3);

  26.                 list.Add(u);
  27.                 list.Add(e);
  28.                 list.Add(c);
  29.             }
  30.             return list;
  31.         }
  32.     }

今天学习感悟:
    多表连接什么的,还真是靠的是别人啊~~我脑子里根本没这东西,不过龙哥偶尔的提问还真的是可以回答啊~~我觉得我最近有点二,不太能听得懂龙哥问的,得过个几分钟才反应的过来,不过倒是还好,至少答对了= =,好吧~我又不在状态了= =!!!怎么又不在状态了啊!!!讨厌!!!小逗比= =你别逗比了行不行啊~~~~~~~~拼的时候到了!!别闹!!!
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值