Click here to Skip to main content
15,898,371 members
Home / Discussions / Database
   

Database

 
QuestionLoad file in SQL Server from FileSystem Pin
JoZ CaVaLLo19-May-08 23:24
JoZ CaVaLLo19-May-08 23:24 
QuestionSql server reporting service 2005 - Drill down problem Pin
veereshIndia19-May-08 22:26
veereshIndia19-May-08 22:26 
AnswerCP Ignore Pin
leckey20-May-08 3:27
leckey20-May-08 3:27 
QuestionSql Server 2005 reporting service-Toggle problem Pin
veereshIndia19-May-08 22:15
veereshIndia19-May-08 22:15 
QuestionPartially solved SQL SELECT won't select more than two columns [modified] Pin
Vaclav_19-May-08 16:59
Vaclav_19-May-08 16:59 
AnswerRe: SQL SELECT won't select more than two columns Pin
Mycroft Holmes19-May-08 23:16
professionalMycroft Holmes19-May-08 23:16 
GeneralRe: SQL SELECT won't select more than two columns Pin
Vaclav_20-May-08 2:50
Vaclav_20-May-08 2:50 
QuestionHow can i get max Point and Min Date using SQL [modified] Pin
mangrovecm19-May-08 16:20
mangrovecm19-May-08 16:20 
Dear all,
I have a 'Games' table in testxyz db following:
create database testxyz
go
use testxyz
go
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Games]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Games]
GO

CREATE TABLE [dbo].[Games] (
[UserID] [int] IDENTITY (1, 1) NOT NULL ,
[UserName] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Point] [int] NULL ,
[Dates] [datetime] NULL
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[Games] ADD
CONSTRAINT [DF_Users_Dates] DEFAULT (getdate()) FOR [Dates],
CONSTRAINT [PK_Users] PRIMARY KEY CLUSTERED
(
[UserID]
) ON [PRIMARY]
GO
--Insert data:
DELETE FROM [Games]
GO
SET IDENTITY_INSERT[Games] ON
GO
INSERT INTO [dbo].[Games](UserID,UserName,Point,Dates)
VALUES(1,'C.John',10,'5/19/2008 7:20:59 PM')
GO
INSERT INTO [dbo].[Games](UserID,UserName,Point,Dates)
VALUES(2,'C.John',12,'5/18/2008 7:10:59 PM')
GO
INSERT INTO [dbo].[Games](UserID,UserName,Point,Dates)
VALUES(3,'C.John',6,'5/17/2008 7:22:59 PM')
GO
INSERT INTO [dbo].[Games](UserID,UserName,Point,Dates)
VALUES(4,'C.John',20,'5/19/2008 7:45:59 PM')
GO
INSERT INTO [dbo].[Games](UserID,UserName,Point,Dates)
VALUES(5,'A.Jerry',4,'5/19/2008 7:28:59 PM')
GO
INSERT INTO [dbo].[Games](UserID,UserName,Point,Dates)
VALUES(6,'A.Jerry',8,'5/19/2008 7:19:59 PM')
GO
INSERT INTO [dbo].[Games](UserID,UserName,Point,Dates)
VALUES(7,'A.Jerry',10,'4/1/2008 7:19:59 PM')
GO
INSERT INTO [dbo].[Games](UserID,UserName,Point,Dates)
VALUES(8,'A.Jerry',67,'4/1/2008 7:19:59 PM')
GO
INSERT INTO [dbo].[Games](UserID,UserName,Point,Dates)
VALUES(9,'Nancy',50,'5/11/2008 7:19:59 PM')
GO
INSERT INTO [dbo].[Games](UserID,UserName,Point,Dates)
VALUES(10,'Nancy',10,'5/21/2008 7:19:59 PM')

GO
INSERT INTO [dbo].[Games](UserID,UserName,Point,Dates)
VALUES(11,'Nancy',78,'5/25/2008 7:19:59 PM')
GO
INSERT INTO [dbo].[Games](UserID,UserName,Point,Dates)
VALUES(12,'A.Jerry',78,'5/26/2008 7:19:59 PM')
SET IDENTITY_INSERT[Games] OFF
GO

Now, I want to get rows which have maximum 'Point' and minimum 'Dates'.
If Point of user is the same. it gets a row with minimum 'Dates' condition. Note that result will sort by Point 'DESC'. UserName do not repeat in the result.

In data above. Expected result is:
UserID | UserName | Point | Dates
11 | Nancy |78 | 5/25/2008 7:19:59 PM
12 | A.Jerry |78 | 5/26/2008 7:19:59 PM
4 | C.John |20 | 5/19/2008 7:45:59 PM


Please help me!

Thanks a lot

mangrovecm

(-,-)am from VietNamese.

modified on Tuesday, May 20, 2008 9:13 PM

AnswerRe: How can i get max Point and Min Date using SQL Pin
WoutL19-May-08 21:32
WoutL19-May-08 21:32 
GeneralRe: How can i get max Point and Min Date using SQL Pin
mangrovecm20-May-08 3:52
mangrovecm20-May-08 3:52 
GeneralRe: How can i get max Point and Min Date using SQL Pin
WoutL20-May-08 20:02
WoutL20-May-08 20:02 
QuestionQuery Help Pin
Hulicat19-May-08 13:17
Hulicat19-May-08 13:17 
AnswerRe: Query Help Pin
Blue_Boy19-May-08 21:51
Blue_Boy19-May-08 21:51 
GeneralRe: Query Help Pin
Hulicat20-May-08 3:50
Hulicat20-May-08 3:50 
GeneralRe: Query Help Pin
Blue_Boy20-May-08 4:03
Blue_Boy20-May-08 4:03 
QuestionTransaction question Pin
kensai19-May-08 5:17
kensai19-May-08 5:17 
AnswerRe: Transaction question Pin
J4amieC19-May-08 5:39
J4amieC19-May-08 5:39 
GeneralRe: Transaction question Pin
kensai19-May-08 5:52
kensai19-May-08 5:52 
QuestionOne more thing Pin
kensai19-May-08 6:44
kensai19-May-08 6:44 
QuestionHow to read an database table step by step (with ADO) Pin
harry7988019-May-08 3:35
harry7988019-May-08 3:35 
AnswerRe: How to read an database table step by step (with ADO) Pin
Adeel Chaudhry19-May-08 5:48
Adeel Chaudhry19-May-08 5:48 
AnswerRe: How to read an database table step by step (with ADO) Pin
Mycroft Holmes19-May-08 23:29
professionalMycroft Holmes19-May-08 23:29 
QuestionAppending the value with NULL value Pin
Revathij19-May-08 2:40
Revathij19-May-08 2:40 
AnswerRe: Appending the value with NULL value Pin
J4amieC19-May-08 3:14
J4amieC19-May-08 3:14 
Questionwhat is the use of indexes , when i creating table it already creating one index.......... Pin
Shaik Haneef19-May-08 0:52
Shaik Haneef19-May-08 0:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.