Home > Database > Mysql Tutorial > SQLServer基础语法实例应用(二)

SQLServer基础语法实例应用(二)

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 16:20:28
Original
1088 people have browsed it

-- 测试数据:[a] if object_id('[a]') is not null drop table [a] go create table [a]([ID] int,[品名] varchar(6),[入库数量] int,[入库时间] datetime) insert [a] select 1,'矿泉水',100,'2013-01-02' union all select 2,'方便面',60,'2013-01-03' un

--> 测试数据:[a]

if object_id('[a]') is not null drop table [a]

go

create table [a]([ID] int,[品名] varchar(6),[入库数量] int,[入库时间] datetime)

insert [a]

select 1,'矿泉水',100,'2013-01-02' union all

select 2,'方便面',60,'2013-01-03' union all

select 3,'方便面',50,'2013-01-03' union all

select 4,'矿泉水',80,'2013-01-04' union all

select 5,'方便面',50,'2013-01-05'

 

select a.[品名],a.[入库数量],b.[最后入库时间] from [test] a  ,

(select  [品名],max([入库时间]) as '最后入库时间' from [test]  group by [品名]) b

where a.[品名]=b.[品名]

 

/*

品名     入库数量        最后入库时间

------ ----------- -----------------------

方便面    60          2013-01-05 00:00:00.000

方便面    50          2013-01-05 00:00:00.000

方便面    50          2013-01-05 00:00:00.000

矿泉水    100         2013-01-04 00:00:00.000

矿泉水    80          2013-01-04 00:00:00.000

 

(5 行受影响)

 

*/

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Problem with tp6 connecting to sqlserver database
From 1970-01-01 08:00:00
0
0
0
Unable to connect to SQL Server in Laravel
From 1970-01-01 08:00:00
0
0
0
Methods of parsing MYD, MYI, and FRM files
From 1970-01-01 08:00:00
0
0
0
SQLSTATE: User login failed
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template