<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>
SQL基础第十八章
最新推荐文章于 2022-05-03 10:23:15 发布