求SQL查询语句具体如下 sql语句查询具体日期
sql查询语句大全
:select * from table1 where 范围 :insert into table1(field1,field2) values(value1,value2)delete from table1 where 范围 :update table1 set field1=value1 where 范围 :select * from table1 where field1 like ’%value1%’ 排序:select * from table1 order by field1,field2 [desc] 总数:select count as totalcount from table1 求和:select sum(field1) as sumvalue from table1 平均:select avg(field1) as avgvalue from table1 最大:select max(field1) as maxvalue from table1 最小:select min(field1) as minvalue from table1[separator
求SQL查询语句
--得到所有的最高级单位
select * from com_unit where parent_unit is null
--得到有一个高级单位的
select * from com_unit where parent_unit is not null and not parent_unit like '%,%'
--得到有多个高级单位的
select * from com_unit where parent_unit is not null and parent_unit like '%,%'
//====
楼主, 你的表结构有点难受的说,
既然一个公司可能有多个上级 那就用一对多的关联
建议你这样建表
1.公司表 (编号, 名称)
CREATE TABLE [dbo].[com] (
[num] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[name] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL
) ON [PRIMARY]
GO
2.关系表 (公司, 上级公司)
CREATE TABLE [dbo].[com_com] (
[comNum] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[parentComNum] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL
) ON [PRIMARY]
GO
这样的话更复杂的查询写起来会简单
sql的查询语句
都是最基本的sql语句,先把创建表的给你。后面的太多了,有空再写。
(一)
1.
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Dept]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Dept]
GO
CREATE TABLE [dbo].[Dept] (
[Dno] [Char] (4)NOT NULL primary key,
[Ename] [char] (20) NOT NULL ,
[Dnum ] [int] check(Dnum >=0)
UNIQUE (Ename)
) ON [PRIMARY]
GO
2.
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Employee]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Employee]
GO
CREATE TABLE [dbo].[Employee] (
[Eno] [Char] (6)NOT NULL primary key,
[Dname] [char] (16) NOT NULL ,
[Esex ] [char](1) CHECK(Esex='F' OR Esex='M'),
[Eage] [Smallint] check(Dnum >=0),
[Esalary] [Money](1) check(Smallint >=16 and Smallint<=60),
[Eduty] [char](15) DEFAULT'助教'),
[Dno] [char](4) FOREIGN KEY (Dno) REFERENCES Dept(Dno)
) ON [PRIMARY]
GO
sql查询语句大全
1、Alter table LOANS add [备注说明] varchar(20)
2、Select 出版社,KCSL as 库存量,总价/KCSL as 平均单价 From (Select 出版社,count(索书号) as KCSL,sum(价格) as 总价 from BOOKS Group by 出版社) As 库存表 Order by 库存量 Desc
3、Select Left(借书证号,2) as 年级,Count(*) as 人数 from BORROWER Order by 年级
4、Select 出版社 from BOOK Where 价格>200 group by 出版社
5、Select 借书证号,Count(图书登记号) As 借书数量 from LOANS Group by 借书证号 having Count(图书登记号) >5 order by 借书证号 Desc
(2)
1、Select 性别,Min(年龄) as 最小年龄 From student Group by 性别
2、Select 学号,门数 as 选课门数,总成绩/门数 as 平均成绩 From (Select 学号,Count(*) as 门数,Sum(成绩) as 总成绩 from sc Group by 学号) As 成绩表
3、Select 课程号,Max(成绩) as 最高分,Min(成绩) as 最低分,Sum(成绩)/Count(*) As 平均分 From SC Group by 课程号 order by 平均分 Desc