我有这张桌子
create table student (
stu_id int,
s_name nvarchar(max),
s_subject nvarchar(max),
)
Run Code Online (Sandbox Code Playgroud)
这是数据
insert into student values(123,'pammy','English');
insert into student values(123,'pammy','Maths');
insert into student values(123,'pammy','Chemistry');
insert into student values(124,'watts','Biology');
insert into student values(125,'Tom','Physics');
insert into student values(125,'Tom','Computer';
insert into student values(125,'Tom','ED';
Run Code Online (Sandbox Code Playgroud)
所以我想检索已发生两次以上的记录.我的代码是
select stu_id,s_Name
from student
group by stu_id,s_Name
having count(stu_id) >2 ;
Run Code Online (Sandbox Code Playgroud)
结果很完美.
但是当我想要s_subject它时也没有选择任何行.我不知道为什么.
select stu_id,s_Name,s_subject
from student
group by stu_id,s_Name,s_subject
having count(stu_id) >2 ;
Run Code Online (Sandbox Code Playgroud) 我的桌子是 -
create table mobile
(
id integer,
m_name varchar(20),
cost integer
)
Run Code Online (Sandbox Code Playgroud)
而价值观是 -
insert into mobile values(10,'NOkia',100);
insert into mobile values(11,'Samsung',150);
insert into mobile values(12,'Sony',120);
Run Code Online (Sandbox Code Playgroud)
我知道如何计算柱成本的平均值,我的代码是 -
select avg(cost) from mobile;
Run Code Online (Sandbox Code Playgroud)
结果是123
但我想计算平均值,然后也显示差异.我能够这样但但是,我无法在选择查询中添加avg列 -
我的代码是---
SELECT id, m_name as "Mobile Name", cost as Price,avg(cost) as Average,
cost-(select avg(cost) from mobile) as Difference FROM mobile
group by id,m_name,cost;
Run Code Online (Sandbox Code Playgroud)
输出是 -
id Mobile Name Price Average Difference
10 Nokia 100 100 -23
11 Samsung 150 150 27
12 Sony …Run Code Online (Sandbox Code Playgroud) 我有账户表 -
create table account
(
acct_id int,
cust_id int,
cust_name varchar(20)
)
insert into account values(1,20,'Mark');
insert into account values(2,23,'Tom');
insert into account values(3,24,'Jim');
Run Code Online (Sandbox Code Playgroud)
我想创建一个触发器,它将确保不能在帐户表中插入或更新记录,其中acct_id为2,cust_id为23.
我的代码是 -
create trigger tri_account
before insert or update
on account
for each row
begin
IF (:new.acct_id == 2 and :new.cust_id == 23) THEN
DBMS_OUTPUT.PUT_LINE('No insertion with id 2 and 23.');
rollback;
END IF;
end;
Run Code Online (Sandbox Code Playgroud)
所以这个触发器是创建的,但是有编译错误.现在,当我插入任何acct_id为2且cust_id为23的记录时,它会执行allow.但是我收到错误说 ORA-04098:触发'OPS $ 0924769.TRI_ACCOUNT'无效且重新验证失败
我不明白这一点.我也希望显示一条消息,说明不能插入.请帮忙...