数据库语言,内连接,左外连接,右外连接,外键,遍历器

          我们今天学习了数据库语言,有左外连接,右外连接,内连接,还有具体的查询语句。

 


1.内连接:(两种方法)


 

select users.name, cart.amount, price from users as users

Inner join cart on users.id=cart.uid

 

Select  u.name,c.amount,price from users as u

Inner join cart on u.id=c.uid

 


2.左外连接:


 

Select  u.name,c.amount, c.price from users as u

Left join cart as c on u.id=c.uid

 


3.右外连接:


 

Select u.name,c.amount, c.price from users as u

Right join cart as c on u.id=c.uid

 


4.查询语句:


 

select  name  from  users  where  name  like  ‘%99%’

 

Select  name, age  from  users  where  age  is  null

 

Select  name, age  from  users  where  age  is  not  null

 

Select  name,age  from  users  where  age  between 21 and 29

 

Select  name,age  from  users  where  age>=21  and  age<=29

 

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)  最大值 from  users

 

Select  min(age)  最小值 from  users

 

Select  count(*)  总人数 from  users

 

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

 

Select  id,name ,   avg(age)  最大年龄 from  users  gruoup  by  id,name

 

声明:此篇文档时来自于【狗刨学习网】社区-unity极致学院,是网友自行发布的Unity3D学习文章,如果有什么内容侵犯了你的相关权益,请与官方沟通,我们会即时处理。

5.外键:



Alter  table  cart  add  constraint  gf_users  foreign  key  (uid) references  users (id)

 

Alter  table  cart  add  constraint  gh_users2  foreign  key (uid)references users2  (name)

 


6.遍历器:



 Foreach (Equip  s  in  list)

{

 console.Write (s.Id+”  ”+s.Name+”  ”+s.price+”  ”+s.Amount+”  ”+s.Remark);

}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值