SQL基础第十八章

<html>
<head>
<title>第十八章if then else和子查询</title>

</head>
<style>
pre{font-size:0.5cm;color:blue;font-weight:bold}
p,center{font-size:1cm;color:red}
</style>
<body bgcolor=gray>
<pre>
<p>第十八章if,then,else和子查询</p>
Access中的Immediate If(iif)函数:
iif(表达式,真值,假值)如果表达式为真,则函数为真值,如果表达式为假,则函数为假值。如果表达式不知道。函数仍为假值。测试中用到的条件可以是任何SQL条件。
任务:显示使用该函数的SQL语句,用carrots代替午餐菜单中的broccoli.
select iif(description=broccoli,carrots,description) as new_menu,
price
from 1_foods;
任务:列出食物及其价格,给价格大于¥2.00的食物添加消息。expensive item.按字母顺序列出食物。
select description,price,
iif(price>2.0,expensive item,' ') as message
from 1_foods
order by description;
任务:将原表的cost列分解为两列:debits,credits
select item,
iif(cost<0,cost,' ') as debits,
iif(cost<=0,' ',cost) as credits
from sec1512_finances
order by item;
SQL中不存在变量,现在讨论将变量引入SQL的方法,参数查询和子查询。
Access中的参数查询。
select *
from L_employees
where dept_code=[enter a valid department code];
方括号内的文本代表一个参数。
实际的文本做提示信息。
任务二:要求运行查询的人输入开始日期和结束日期。
select * 
from 1_employees
where hire_date between[enter beginning date]and[ending date]
order by hire_date;
子查询:输入另一个select语句中的select语句称为子查询。,
<hr align=left size=3 color=red width=80%>
<p><a href="首页.html">返回首页</a></p>
</pre>
</body>
</html>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值