CREATE PROCEDURE GetArrangingInfoByCauseOrder
(
@i int
)
AS
select * from testtable
where Period % 10 =@i
--group by RoomID --要这个做什么?
order by Period
GO
(
@i int
)
AS
select * from testtable
where Period % 10 =@i
--group by RoomID --要这个做什么?
order by Period
GO
解决方案 »
- 如何判断字符串中第一个字母的位置?
- 关于一个基础的数据库设计(图书馆目录问题)
- 为何这两种查询的结果不一样?
- 如果数据库中存在名为"aaaa"的用户自定义函数,则删除这个函数, SQL语句要如何写??
- 由于水平差,我的日期全部用字符型,如20050607这种格式,据说不好,可是全改太麻烦了,如何办?
- 关于登陆到远程SQL服务器的问题,只是觉得麻烦,有没有好的方法?
- 请教下面的SQL语句如何改写?
- 如何通过ID号 删除多个表
- 高手帮忙:如何把mssql数据库中的数据生成到.sql 成 insert into ......等
- 小问题!!
- 关于‘restore filelistonly from disk’在VB中使用的问题。
- 我该怎样设计这个表
--group by RoomID
create table 教室信息表(编号 int primary key,教室名称 varchar(10))
insert 教室信息表 select 1,'主楼100'
union all select 2,'主楼101'
union all select 3,'主楼102'create table 课程信息表(编号 int primary key,课程名称 varchar(10))
insert 课程信息表 select 1,'编译'
union all select 2,'组成'
union all select 3,'离散'
union all select 4,'高数'
union all select 5,'汇编'
union all select 6,'英语'
union all select 7,'数据库'
union all select 8,'OS'create table 上课安排表(教室编号 int,星期 int,节 varchar(10),课程编号 int)
insert 上课安排表 select 2,1,'第一节',1
union all select 2,4,'第一节',2
union all select 2,1,'第二节',3
union all select 2,2,'第二节',4
union all select 2,3,'第二节',5
union all select 2,2,'第三节',6
union all select 2,5,'第三节',7
union all select 2,1,'第四节',7
go--查询
select a.教室名称,ab.节
,周一=max(case 星期 when 1 then b.课程名称 else '' end)
,周二=max(case 星期 when 2 then b.课程名称 else '' end)
,周三=max(case 星期 when 3 then b.课程名称 else '' end)
,周四=max(case 星期 when 4 then b.课程名称 else '' end)
,周五=max(case 星期 when 5 then b.课程名称 else '' end)
from 上课安排表 ab
join 教室信息表 a on a.编号=ab.教室编号
join 课程信息表 b on b.编号=ab.课程编号
group by a.教室名称,ab.节
go--删除测试
drop table 上课安排表,教室信息表,课程信息表/*--测试结果教室名称 节 周一 周二 周三 周四 周五
---------- ---------- ---------- ------- --------- ---------- ----------
主楼101 第二节 离散 高数 汇编
主楼101 第三节 英语 数据库
主楼101 第四节 数据库
主楼101 第一节 编译 组成 (所影响的行数为 4 行)
--*/
这里面的“group by a.教室名称,ab.节”是什么意思嫩?
那你查询的结果集合里面必须包括 group by 后面跟的字段名称
比如正确: SELECT ID FROM TestTable GROUP BY ID
错误: SELECT * FROM TestTable GROUP BY id
id subject isUse
1 a 1
2 a 1
3 a 0
4 a 0
5 b 1
6 b 1
7 b 0
8 b 0
9 c 1
10 c 1
我想得到这样的结果
id
3
7即 每个栏目(a,b,c)里,第一个isuse=0的纪录
select id=min(id) from 表 where isuse=0 group by subject