sql高级查询语句 麻烦大家了

问题描述

sql高级查询语句 麻烦大家了

--28)查询选修了课程名为“数据库”的学生的学号和姓名。
select sname,sno
from course,student
where course.cno in(
select cno
from course
where cname='sql') and course.cname=student.sno
group by sname
having count(cname)='sql'

显示错误 出不来

解决方案

sql高级查询语句

解决方案二:

第六行中的 course.cname=student.sno 能相等吗?

解决方案三:

count(cname)='sql'这是什么?数量为'sql'?还有,把course和student两个关系贴出来吧。

解决方案四:

这个貌似不好解决啊,题主自己看看log吧

解决方案五:

count(cname)是统计了,结果是一个数字,不可能等于'sql'

解决方案六:

1、group by sname 结果是查不出sno的。
2、count(cname)的结果是哥数字,不可能为"sql"。

解决方案七:

select Sno,Sname
from Student
where Sno in
(select Sno
 from SC
 where Cno in
 (select Cno
  from Course
  where Cname='sql'))

试试这个

解决方案八:

课程表:
Course(Cno,Cname, Ccredit(学分)),其中Cno为主键
学生选课表:
SC(Sno(学号),Cno(课程),Grade(成绩)),其中Sno,Cno的组合为主键 'sql'是他选的课程是sql

1.先选到sql课程的Cno。
2.在学生选课表中选择Cno出现在1中的记录,然后对Sno执行去重。

    SELECT distinct Sno,Cno
    FROM SC s
    WHERE s.Cno IN(
        SELECT c.Cno
        FROM Course c
        WHERE c.Cname='sql'
    )

解决方案九:

count(cname)是统计了,结果是一个数字,不可能等于'sql'

解决方案十:

having count(cname)='sql'这句先去掉试试

时间: 2024-07-29 03:52:00

sql高级查询语句 麻烦大家了的相关文章

SQL Server SQL高级查询语句小结_MsSql

Ø 基本常用查询 --select select * from student; --all 查询所有 select all sex from student; --distinct 过滤重复 select distinct sex from student; --count 统计 select count(*) from student; select count(sex) from student; select count(distinct sex) from student; --top

SQL Server SQL高级查询语句小结

Ø 基本常用查询 --select select * from student; --all 查询所有 select all sex from student; --distinct 过滤重复 select distinct sex from student; --count 统计 select count(*) from student; select count(sex) from student; select count(distinct sex) from student; --top

关于sql server查询语句的写法。

问题描述 关于sql server查询语句的写法. 怎样写一个查询语句select distinct ID from TrainTime order by ID select Station from TrainTime where S_No='1'order by ID select Stationfrom TrainTime where D_Time='-' order by ID 怎样把这3个查询语句写为一句啊,让查询查来的结果为这3列数据. 因为我想建一个表,为3列,列名为:列车车次.起

sql 高级查询运算词 UNION EXCEPT right及外部连接

sql 高级查询运算词 union except right及外部连接 a: union 运算符 union 运算符通过组合其他两个结果表(例如 table1 和 table2)并消去表中任何重复行而派生出一个结果表.当 all 随 union 一起使用时(即 union all),不消除重复行.两种情况下,派生表的每一行不是来自 table1 就是来自 table2. sql union 语法 select column_name(s) from table_name1 union selec

java-一个纠结的sql分组查询语句

问题描述 一个纠结的sql分组查询语句 是这样的 数据库里有一张 宿舍用电表(宿舍号,时间,电表度数) dormitoryElectric(dormitory,time,electric) 里面存的是每个小时电表上的度数,那我想查询所有宿舍近7天的每天用电度数要怎么写. 效果大概是这样的: 宿舍1 第一天用电度数 第二天用电度数 第三天用电度数 ... 宿舍2 第一天用电度数 第二天用电度数 第三天用电度数 ... 第二天用电度数应该是第二天的最后一次电表度数减去第一天的最后一次电表度数 解决方

sql-【SQL求助】用SQL Server查询语句中,IN 的使用问题。

问题描述 [SQL求助]用SQL Server查询语句中,IN 的使用问题. 我想查询一辆车在一个月内的记录.于是编写了如下代码: select * from 北京车辆能耗数据.dbo.北京朝批商贸股份有限公司 where ( [列 0] in ('京AC3537') and CAST ([列 2] as datetime)>'2013/11/1 00:00:00' and CAST ([列 2] as datetime)<'2013/12/1 00:00:00' ) order by CAS

SQL嵌套查询语句的报错问题

问题描述 SQL嵌套查询语句的报错问题 5C String sql = ""select * from msgInfo where ID in(select top 15 ID from msgInfo where chatRoom=? Order by chatTime DESC) order by chatTime""; String userName=session.getAttribute(""_USER"").toS

sql查询-sql求查询语句 !!!

问题描述 sql求查询语句 !!! 我有一张表 序号 姓名 编号 学科_1 成绩_1 学科_2 成绩_2 学科_3 成绩_3 1 张三 1001 A学科 60 B学科 70 C学科 80 2 李四 1002 A学科 70 B学科 80 C学科 90 3 王五 1003 A学科 60 B学科 80 C学科 90 学科可能有很多,不确定!可能还有 学科_4 成绩_4 想要实现的结果 序号 查询张三的记录结果 序号 姓名 编号 A学科 b学科 C学科 未知学科 1 张三 1001 60 70 80 未

ruby sql select 查询语句用法

ruby sql select 查询语句用法 require 'mysql教程' m = Mysql.new("localhost","ruby","secret","maillist") r = m.query("SELECT * FROM people ORDER BY name") r.each_hash do |f|   print "#{f['name']} - #{f['email']