① sql语句筛选及格成绩
以下语句可实现只显示同学的及格成绩:
select 学号,语文=(case when 语文>=60 then 语文 else Null end),数学=(case when 数学>=60 then 数学 else Null end),英语=(case when 英语>=60 then 英语 else Null end) from 成绩表 where 语文>=60 or 数学>=60 or 英语>=60
② 请问sql表内如何筛选数据
select 编号, 客户名称, 日期, 品名, 型号, 数量, 材质, 单价, 备注, 已发货数量 from [表] where 数量<>已发货数量
③ 用sql语句进行筛选
select姓名from表where课程!='A'
④ SQL怎么取出每个科目前三名并按科目和分组排列
select B1.姓名,B1.科目,B1.分数 from B B1 where(select count(1) from B where 科目=B1.科目 and 分数〉=B1.分数)〈=3 order by B1.科目,B1.分数;
⑤ 用一条SQL(Mysql)语句查询出下表,有2个科目80分以上的人的名字和对应的科目名。
create table stu
(
[name] varchar(10),
[course] varchar(10),
[score] int,
);
insert into stu values('tom','x',80);
insert into stu values('tom','y',75);
insert into stu values('tom','z',90);
insert into stu values('li','x',90);
insert into stu values('li','y',60);
insert into stu values('wang','x',80);
insert into stu values('wang','z',90);
select * from stu;
select b.* from
(select name,count(name) as c from stu where score>=80 group by name) as a,stu b
where a.name=b.name and a.c>=2 and b.score>=80;
⑥ access的SQL语句,写一个能筛选出最受欢迎的人的语句
可以把同一个教师,不同科目的好评分开。如果不分开,把中间的科目名全部去掉就行了。
select N.科目名,N.教师ID, N.教师姓名,M.HPL from
(select max(e.b/f.a) AS HPL
from ((select 科目名,教师ID, 教师姓名, count(*) as b from table where hp=-1 group by 科目名,教师ID, 教师姓名)e
left join
(select 科目名,教师ID, 教师姓名, count(*) as a from table group by 科目名,教师ID, 教师姓名)f
on f.科目名=e.科目名 and f.教师ID=e.教师ID and e.教师姓名=f.教师姓名 )
) M
left join
(select e.科目名,e.教师ID, e.教师姓名,e.b/f.a AS HPL
from ((select 科目名,教师ID, 教师姓名, count(*) as b from table where hp=-1 group by 科目名,教师ID, 教师姓名)e
left join
(select 科目名,教师ID, 教师姓名, count(*) as a from table group by 科目名,教师ID, 教师姓名)f
on f.科目名=e.科目名 and f.教师ID=e.教师ID and e.教师姓名=f.教师姓名 )
) N
ON N.HPL=M.HPL
如果需要第个科目最受欢迎的教师,
select N.科目名,N.教师ID, N.教师姓名,M.HPL from
(select e.科目名,max(e.b/f.a) AS HPL
from ((select 科目名,教师ID, 教师姓名, count(*) as b from table where hp=-1 group by 科目名,教师ID, 教师姓名)e
left join
(select 科目名,教师ID, 教师姓名, count(*) as a from table group by 科目名,教师ID, 教师姓名)f
on f.科目名=e.科目名 and f.教师ID=e.教师ID and e.教师姓名=f.教师姓名 )
gropy by e.科目名
) M
left join
(select e.科目名,e.教师ID, e.教师姓名,e.b/f.a AS HPL
from ((select 科目名,教师ID, 教师姓名, count(*) as b from table where hp=-1 group by 科目名,教师ID, 教师姓名)e
left join
(select 科目名,教师ID, 教师姓名, count(*) as a from table group by 科目名,教师ID, 教师姓名)f
on f.科目名=e.科目名 and f.教师ID=e.教师ID and e.教师姓名=f.教师姓名 )
) N
ON N.HPL=M.HPL
⑦ sql查询结果筛选
select id,max(user time)
from x
group by id
user time 为时间类型才有效
⑧ 在SQL Server数据库中,查一个人同时至少选择两种科目的学号应该怎么写啊
大概引用楼上的楼上的:
科目表: sid name;
个人信息表: tid name ;
成绩表: id score sid tid;
SELECT tid as 学号, COUNT(sid) AS 科目数 FROM 成绩表 GROUP BY tid HAVING COUNT(sid) >= 2
⑨ 怎么用SQL查询结果的会计科目 显示包括上级科目名称
字段里面添加子查询获取上级科目,再用concat函数拼接自己的会计科目,整个查询sql应该是select id,concat((select name from 表名 where id = left(a.id)limit 1),“\”,a.name) from 表名 a。
⑩ sql 按科目查询查询
CREATE TABLE [Test] (
[id] [int] IDENTITY (1, 1) NOT NULL ,
[name] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[subject] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[Source] [numeric](18, 0) NULL
) ON [PRIMARY]
GO
INSERT INTO [test] ([name],[subject],[Source]) values (N'张三',N'语文',60)
INSERT INTO [test] ([name],[subject],[Source]) values (N'李四',N'数学',70)
INSERT INTO [test] ([name],[subject],[Source]) values (N'王五',N'英语',80)
INSERT INTO [test] ([name],[subject],[Source]) values (N'王五',N'数学',75)
INSERT INTO [test] ([name],[subject],[Source]) values (N'王五',N'语文',57)
INSERT INTO [test] ([name],[subject],[Source]) values (N'李四',N'语文',80)
INSERT INTO [test] ([name],[subject],[Source]) values (N'张三',N'英语',100)
Go
交叉表语句的实现:
--用于:交叉表的列数是确定的
select name,sum(case subject when '数学' then source else 0 end) as '数学',
sum(case subject when '英语' then source else 0 end) as '英语',
sum(case subject when '语文' then source else 0 end) as '语文'
from test
group by name