1、请看下面数据库结构回答问题
id(主键) P_name(物品名称) S_money(销售额) S_date(销售日期)
1 苹果 1000 2008-3-16
2 香蕉 1000 2008-3-16
3 梨子 500 2008-3-16
4 苹果 100 2008-3-16
5 梨子 200 2008-3-16
6 香蕉 100 2008-3-15
(1)写出查找出2008-3-16日销售总额大于1000元的物品及销售总额的SQL
(2)写出统计苹果的销售总额的SQL。
(3)写出销售总额小于1000的物品及销售总额。
2、写出重命名表(test_table)字段(test_name to test_name2)的SQL语句.
3、写出从字符串“ABCDEFG”取出前4位字符和SQL语句。
4、得到系统当前日期,输出格式为:YYYY-MM-DD。
5、将字符串“2008”转化为数字
6、在SQLPLUS中返回当前登录用户名称
7、返回字符串“ABCDEFG“ 的长度
8、写出列出表(test)的表结构SQL
长时间未工作,导致所学知识快忘干净了.
拿了一个笔记题来做做,却发现一个都不会了..!
------解决方案--------------------------------------------------------
--(1)写出查找出2008-3-16日销售总额大于1000元的物品及销售总额的SQL
select
P_name(物品名称),sum( S_money(销售额) )
from
table t
where
t.S_date(销售日期) = to_date('2008-3-16','yyyy-mm-dd')
group by P_name(物品名称)
having sum( S_money(销售额) ) > 1000
--$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
--(2)写出统计苹果的销售总额的SQL。
select
sum(S_money(销售额))
from
table t
where
t.P_name(物品名称)='苹果'
--$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
--(3)写出销售总额小于1000的物品及销售总额。
select
P_name(物品名称),sum( S_money(销售额) )
from
table t
group by P_name(物品名称)
having sum( S_money(销售额) ) < 1000
--$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
--2、写出重命名表(test_table)字段(test_name to test_name2)的SQL语句.
字段 alter test_table tt rename column test_name to test_name2; --9i
--$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
--3、写出从字符串“ABCDEFG”取出前4位字符和SQL语句。
select substr('ABCDEFG',4) a from dual
--$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
--4、得到系统当前日期,输出格式为:YYYY-MM-DD。
select to_char(sysdate,'yyyy-mm-dd') a from dual
--$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
--5、将字符串“2008”转化为数字
select to_number('2008') a from dual
--$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
--6、在SQLPLUS中返回当前登录用户名称
show user
--$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
--7、返回字符串“ABCDEFG“ 的长度
length(trim('ABCDEFG'))
--$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
--8、写出列出表(test)的表结构SQL
desc test;