October 19, 2013 at 10:33 pm
Hi all,
WOULD IF I CAN HELP WITH THAT, I HAVE MY INNER JOIN TABLE EXISTENCIA_BODEGA WITH THE TABLES AND CELLAR TRANSACCION_INV, I WANT TO BRING IS ALL THAT HAD LAST ARTICLE TRANSACTION, SO HAVE FECHA_HORA_TRANSAC COLUMN, BUT I IS BRINGING ALL THE TRANSACTION, COULD GUIDE ME ON HOW I CAN TELL ME BRING SQL TRANSACTIONS OF EVERY lAST ARTICLE.
HOW CAN SEE I HAVE A COLUMN BETWEEN A FECHA_HORA_TRANSAC FOR ME TO BRING THE 17/10/2013 2013-10-01, SHOULD COMPLY WITH THESE CONDITIONS.
THANK YOU,
GREETINGS
October 19, 2013 at 10:41 pm
To help us help you, rather than posting a picture of the data, please see the first link under "Helpful Links" in my signature line below and post your data as per that article. Otherwise the answer is simply, express a ROW_NUMBER() over the partitions formed by the articulo column in descending order by fecha_hora_transac in a CTE and select only the rows with a ROW_NUMBER() of "1" from that.
--Jeff Moden
Change is inevitable... Change for the better is not.
October 20, 2013 at 5:25 am
It looks like something along those lines might help (untested due to missing sample data in a ready to use format...):
WITH cte AS
(
SELECT DISTINCT articulo
FROM unknown
)
SELECT
uk.articulo,
uk.bodega,
uk.cant_disponible,
uk.cantidad,
uk.fecha_hora_transac
FROM cte
CROSS APPLY
(
SELECT TOP 1
u.articulo,
u.bodega,
u.cant_disponible,
u.cantidad,
u.fecha_hora_transac
FROM unknown u
INNER JOIN cte ON cte.articulo = u.articulo
ORDER BY u.fecha_hora_transac DESC
)uk
If there's already a normalized table to get the articulo values, use this table instead of the cte.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply