krabby Posted June 4, 2012 at 02:57 PM Report Share #460303 Posted June 4, 2012 at 02:57 PM Boa tarde, Precisava de ajuda. Tenho uma tabela com a seguinte estrutura: ID 1, ID 2, Type, ServerTime 1 325 7 2012-06-04 12:33:22.493 1 324 7 2012-06-03 12:33:22.493 2 333 7 2012-06-01 12:33:22.493 2 334 7 2012-05-31 12:33:22.493 Precisava de listar por exemplo, dentro dos id's que existem (ID 1) o mais antigo de cada. Ou seja, da tabela acima, o que queria obter era: ID 1, ID 2, Type, ServerTime 1 324 7 2012-06-03 12:33:22.493 2 334 7 2012-05-31 12:33:22.493 Consigo fazer com o top 1 mas apenas para 1 registo. Alguem me dá uma ajuda? cumprimentos, Link to comment Share on other sites More sharing options...
pikax Posted June 4, 2012 at 03:03 PM Report Share #460310 Posted June 4, 2012 at 03:03 PM podes fazer varias coisas. faz um group by ServerTime order by Servertime asc, e apanhas o primeiro valor da tabela. Ou podes fazer tambem com um Select dentro do Select Por muito mais que que estude só aprendo uma coisa, que ainda tenho muita coisa para aprender. A beleza de um código está em decompor problemas complexos em pequenos blocos simples. "learn how to do it manually first, then use the wizzy tool to save time." "Kill the baby, don't be afraid of starting all over again. Fail soon, learn fast." Link to comment Share on other sites More sharing options...
pmg Posted June 4, 2012 at 03:15 PM Report Share #460318 Posted June 4, 2012 at 03:15 PM Para facilitar cria uma view com o tempo minimo create view mintime as select id1, min(OCCASION) as m from TABELA group by id1; Depois usa essa view para filtar as linhas da TABELA select TABELA.* from TABELA, mintime where TABELA.id1 = mintime.id1 and TABELA.OCCASION = mintime.m; What have you tried? Não respondo a dúvidas por PM A minha bola de cristal está para compor; deve ficar pronta para a semana. Torna os teus tópicos mais atractivos e legíveis usando a tag CODE para colorir o código! Link to comment Share on other sites More sharing options...
krabby Posted June 4, 2012 at 03:18 PM Author Report Share #460320 Posted June 4, 2012 at 03:18 PM Boas, Obrigado pela sugestões. vou fazer alguns testes com o que indicaram. Já vos dou feedback também1 Obrigado! Link to comment Share on other sites More sharing options...
ricasss Posted June 4, 2012 at 09:54 PM Report Share #460409 Posted June 4, 2012 at 09:54 PM pelo order by tens o que queres Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now