{"id":315,"date":"2023-10-08T19:00:00","date_gmt":"2023-10-08T19:00:00","guid":{"rendered":"https:\/\/datacrazyworld.com\/?p=315"},"modified":"2023-10-08T18:50:51","modified_gmt":"2023-10-08T18:50:51","slug":"funciones-first_value-y-last_value","status":"publish","type":"post","link":"https:\/\/datacrazyworld.com\/index.php\/2023\/10\/08\/funciones-first_value-y-last_value\/","title":{"rendered":"Funciones FIRST_VALUE y LAST_VALUE"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u00bfConoces las funciones <strong>FIRST_VALUE<\/strong> y <strong>LAST_VALUE<\/strong> de <em>T-SQL<\/em>? Si no las conoces, deber\u00edas ya que son unas funciones anal\u00edticas que facilitan muchas consultas. Y si las conoces, tambi\u00e9n deber\u00edas seguir leyendo, porque te explico alguna cosilla que deber\u00edas tener en cuenta si vas a usarlas.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Como su propio nombre indican, FIRST_VALUE devuelve el primer valor de un conjunto ordenado de valores y LAST_VALUE el \u00faltimo.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Ambas funciones siempre van acompa\u00f1adas de la cl\u00e1usula <em>OVER<\/em>, d\u00f3nde se indica el orden que se va a aplicar.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Opcionalmente, puedes aplicar estas funciones sobre particiones, a\u00f1adiendo la cl\u00e1usula <em>PARTITION BY<\/em> dentro del <em>OVER<\/em>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Como no quiero repetir la teor\u00eda, lo mejor es que revises toda la informaci\u00f3n m\u00e1s detallada en las p\u00e1ginas de referencia de Microsoft:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>FIRST_VALUE: <a href=\"https:\/\/learn.microsoft.com\/es-es\/sql\/t-sql\/functions\/first-value-transact-sql?view=sql-server-ver16\" target=\"_blank\" rel=\"noopener\" title=\"Documentaci\u00f3n FIRST_VALUE\">https:\/\/learn.microsoft.com\/es-es\/sql\/t-sql\/functions\/first-value-transact-sql?view=sql-server-ver16<\/a><\/li>\n\n\n\n<li>LAST_VALUE: <a href=\"https:\/\/learn.microsoft.com\/es-es\/sql\/t-sql\/functions\/last-value-transact-sql?view=sql-server-ver16\" target=\"_blank\" rel=\"noopener\" title=\"Documentaci\u00f3n LAST_VALUE\">https:\/\/learn.microsoft.com\/es-es\/sql\/t-sql\/functions\/last-value-transact-sql?view=sql-server-ver16<\/a><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Lo que realmente me interesa contarte, es c\u00f3mo funcionan realmente ambas funciones y evitar que cometas el mismo error que yo comet\u00ed en su d\u00eda. Y lo mejor para ello es usar un ejemplo.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Vamos usar una tabla temporal, con los siguientes valores<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>declare @tabla1 table\r\n(\r\n    id int\r\n    ,importe int\r\n    ,fecha datetime\r\n)\r\n \r\nINSERT INTO @tabla1 (Id,Importe,fecha)\r\nvalues (1,100,'20190101')\r\n,(1,200,'20190102')\r\n,(1,300,'20190103')\r\n,(2,400,'20190101')\r\n,(2,500,'20190102')\r\n,(2,600,'20190103')\r\n \r\nSELECT * from  @tabla1\r\n\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Ahora, con estos datos, queremos sacar de cada ID su primer y su \u00faltimo importe y fecha. El instinto te puede decir que es tan simple como usar FIRST_VALUE y LAST_VALUE, pero \u00a1ojo! \u00a1No! \u00a1Mira lo que hace!<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Select DISTINCT\r\n    id\r\n    ,FIRST_VALUE(importe) OVER(PARTITION BY ID ORDER BY Fecha) as PrimerImporte\r\n    ,FIRST_VALUE(fecha) OVER(PARTITION BY ID ORDER BY Fecha) as FechaPrimerImporte\r\n    ,LAST_VALUE(importe) OVER(PARTITION BY ID ORDER BY Fecha) as UltimoImporte\r\n    ,LAST_VALUE(fecha) OVER(PARTITION BY ID ORDER BY Fecha) as FechaUltimoImporte\r\nfrom @tabla1\r\n\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;Si lanzamos esta SELECT obtenemos la siguiente informaci\u00f3n:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>Id<\/strong><\/td><td><strong>PrimerImporte<\/strong><\/td><td><strong>FechaPrimerImporte<\/strong><\/td><td><strong>UltimoImporte<\/strong><\/td><td><strong>FechaUltimoImporte<\/strong><\/td><\/tr><tr><td>1<\/td><td>100<\/td><td>2019-01-01 00:00:00.000<\/td><td>100<\/td><td>2019-01-01 00:00:00.000<\/td><\/tr><tr><td>1<\/td><td>100<\/td><td>2019-01-01 00:00:00.000<\/td><td>200<\/td><td>2019-01-02 00:00:00.000<\/td><\/tr><tr><td>1<\/td><td>100<\/td><td>2019-01-01 00:00:00.000<\/td><td>300<\/td><td>2019-01-03 00:00:00.000<\/td><\/tr><tr><td>2<\/td><td>400<\/td><td>2019-01-01 00:00:00.000<\/td><td>400<\/td><td>2019-01-01 00:00:00.000<\/td><\/tr><tr><td>2<\/td><td>400<\/td><td>2019-01-01 00:00:00.000<\/td><td>500<\/td><td>2019-01-02 00:00:00.000<\/td><\/tr><tr><td>2<\/td><td>400<\/td><td>2019-01-01 00:00:00.000<\/td><td>600<\/td><td>2019-01-03 00:00:00.000<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Para empezar, me devuelve N l\u00edneas por cada ID, cuando s\u00f3lo deber\u00eda devolver una. Y es que aunque usemos la cl\u00e1usla <em>DISTINCT<\/em>,\u00a0 el LAST_VALUE me devuelve un valor diferente en cada fila: te va diciendo el \u00faltimo lleva hasta el momento de procesar cada una de las l\u00edneas de la tabla particionada por ID.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Como ves, el LAST_VALUE, a mi parecer, es un confuso, as\u00ed que yo no lo uso (al menos en las casu\u00edsticas habituales). Si realmente necesito conocer el \u00daLTIMO valor, lo enfoco por otro lado: \u00abel \u00daLTIMO VALOR no es otro que el 1\u00ba empezando por el final\u00bb, as\u00ed que opto por usar el FIRST_VALUE y simplemente, ordeno al rev\u00e9s.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Select DISTINCT\r\n\tid\r\n\t,FIRST_VALUE(importe) OVER(PARTITION BY ID ORDER BY Fecha) as PrimerImporte\r\n\t,FIRST_VALUE(fecha) OVER(PARTITION BY ID ORDER BY Fecha) as FechaPrimerImporte\r\n\t,FIRST_VALUE(importe) OVER(PARTITION BY ID ORDER BY Fecha DESC) as UltimoImporte\r\n\t,FIRST_VALUE(fecha) OVER(PARTITION BY ID ORDER BY Fecha DESC) as FechaUltimoImporte\r\nfrom @tabla1\r\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Y as\u00ed, el resultado, s\u00ed ser\u00eda el esperado.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>id<\/strong><\/td><td><strong>PrimerImporte<\/strong><\/td><td><strong>FechaPrimerImporte<\/strong><\/td><td><strong>UltimoImporte<\/strong><\/td><td><strong>FechaUltimoImporte<\/strong><\/td><\/tr><tr><td>1<\/td><td>100<\/td><td>2019-01-01 00:00:00.000<\/td><td>300<\/td><td>2019-01-03 00:00:00.000<\/td><\/tr><tr><td>2<\/td><td>400<\/td><td>2019-01-01 00:00:00.000<\/td><td>600<\/td><td>2019-01-03 00:00:00.000<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u00a1Espero haberte ayudado con esta peque\u00f1a explicaci\u00f3n y con este ejemplo!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u00bfConoces las funciones FIRST_VALUE y LAST_VALUE de T-SQL?  Las conozcas o no, deber\u00edas leer este peque\u00f1o post para saber c\u00f3mo funcionan y no errar en su uso.<\/p>\n","protected":false},"author":2,"featured_media":316,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[8,9],"tags":[21,12],"class_list":["post-315","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-sqlserver","category-tsql","tag-sqlserver","tag-tsql"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 4.9.9 - aioseo.com -->\n\t<meta name=\"description\" content=\"\u00bfConoces las funciones FIRST_VALUE y LAST_VALUE de T-SQL? Las conozcas o no, deber\u00edas leer este peque\u00f1o post para saber c\u00f3mo funcionan y no errar en su uso.\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Cristina Tarabini-Castellani Ciordia\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/datacrazyworld.com\/index.php\/2023\/10\/08\/funciones-first_value-y-last_value\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 4.9.9\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n\t\t<meta name=\"twitter:site\" content=\"@DataCrazyWorld\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Funciones FIRST_VALUE y LAST_VALUE - Data Crazy World\" \/>\n\t\t<meta name=\"twitter:description\" content=\"\u00bfConoces las funciones FIRST_VALUE y LAST_VALUE de T-SQL? Las conozcas o no, deber\u00edas leer este peque\u00f1o post para saber c\u00f3mo funcionan y no errar en su uso.\" \/>\n\t\t<meta name=\"twitter:creator\" content=\"@DataCrazyWorld\" \/>\n\t\t<meta name=\"twitter:image\" content=\"https:\/\/datacrazyworld.com\/wp-content\/uploads\/2022\/12\/Color_Small.png\" \/>\n\t\t<meta name=\"twitter:label1\" content=\"Escrito por\" \/>\n\t\t<meta name=\"twitter:data1\" content=\"Cristina Tarabini-Castellani Ciordia\" \/>\n\t\t<meta name=\"twitter:label2\" content=\"Tiempo de lectura estimado\" \/>\n\t\t<meta name=\"twitter:data2\" content=\"3 minutos\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"BlogPosting\",\"@id\":\"https:\\\/\\\/datacrazyworld.com\\\/index.php\\\/2023\\\/10\\\/08\\\/funciones-first_value-y-last_value\\\/#blogposting\",\"name\":\"Funciones FIRST_VALUE y LAST_VALUE - Data Crazy World\",\"headline\":\"Funciones FIRST_VALUE y LAST_VALUE\",\"author\":{\"@id\":\"https:\\\/\\\/datacrazyworld.com\\\/index.php\\\/author\\\/tarabiquetevi\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/datacrazyworld.com\\\/#person\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/datacrazyworld.com\\\/wp-content\\\/uploads\\\/2023\\\/10\\\/TSQLPill.png\",\"width\":1200,\"height\":630,\"caption\":\"T-SQL Pill\"},\"datePublished\":\"2023-10-08T19:00:00+00:00\",\"dateModified\":\"2023-10-08T18:50:51+00:00\",\"inLanguage\":\"es-ES\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/datacrazyworld.com\\\/index.php\\\/2023\\\/10\\\/08\\\/funciones-first_value-y-last_value\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/datacrazyworld.com\\\/index.php\\\/2023\\\/10\\\/08\\\/funciones-first_value-y-last_value\\\/#webpage\"},\"articleSection\":\"SQL Server, tsql, sqlserver, tsql\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/datacrazyworld.com\\\/index.php\\\/2023\\\/10\\\/08\\\/funciones-first_value-y-last_value\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/datacrazyworld.com#listItem\",\"position\":1,\"name\":\"Inicio\",\"item\":\"https:\\\/\\\/datacrazyworld.com\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/datacrazyworld.com\\\/index.php\\\/category\\\/sqlserver\\\/#listItem\",\"name\":\"SQL Server\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/datacrazyworld.com\\\/index.php\\\/category\\\/sqlserver\\\/#listItem\",\"position\":2,\"name\":\"SQL Server\",\"item\":\"https:\\\/\\\/datacrazyworld.com\\\/index.php\\\/category\\\/sqlserver\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/datacrazyworld.com\\\/index.php\\\/category\\\/sqlserver\\\/tsql\\\/#listItem\",\"name\":\"tsql\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/datacrazyworld.com#listItem\",\"name\":\"Inicio\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/datacrazyworld.com\\\/index.php\\\/category\\\/sqlserver\\\/tsql\\\/#listItem\",\"position\":3,\"name\":\"tsql\",\"item\":\"https:\\\/\\\/datacrazyworld.com\\\/index.php\\\/category\\\/sqlserver\\\/tsql\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/datacrazyworld.com\\\/index.php\\\/2023\\\/10\\\/08\\\/funciones-first_value-y-last_value\\\/#listItem\",\"name\":\"Funciones FIRST_VALUE y LAST_VALUE\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/datacrazyworld.com\\\/index.php\\\/category\\\/sqlserver\\\/#listItem\",\"name\":\"SQL Server\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/datacrazyworld.com\\\/index.php\\\/2023\\\/10\\\/08\\\/funciones-first_value-y-last_value\\\/#listItem\",\"position\":4,\"name\":\"Funciones FIRST_VALUE y LAST_VALUE\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/datacrazyworld.com\\\/index.php\\\/category\\\/sqlserver\\\/tsql\\\/#listItem\",\"name\":\"tsql\"}}]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/datacrazyworld.com\\\/#person\",\"name\":\"Cristina Tarabini-Castellani Ciordia\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/datacrazyworld.com\\\/index.php\\\/2023\\\/10\\\/08\\\/funciones-first_value-y-last_value\\\/#personImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/020df7a271c91fd52178caf747ffe0997d2f1113e00f58e77a2878622e27453f?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Cristina Tarabini-Castellani Ciordia\"},\"sameAs\":[\"https:\\\/\\\/twitter.com\\\/DataCrazyWorld\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/cristina-tarabini-castellani\\\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/datacrazyworld.com\\\/index.php\\\/author\\\/tarabiquetevi\\\/#author\",\"url\":\"https:\\\/\\\/datacrazyworld.com\\\/index.php\\\/author\\\/tarabiquetevi\\\/\",\"name\":\"Cristina Tarabini-Castellani Ciordia\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/datacrazyworld.com\\\/index.php\\\/2023\\\/10\\\/08\\\/funciones-first_value-y-last_value\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/020df7a271c91fd52178caf747ffe0997d2f1113e00f58e77a2878622e27453f?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Cristina Tarabini-Castellani Ciordia\"},\"sameAs\":[\"https:\\\/\\\/twitter.com\\\/DataCrazyWorld\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/cristina-tarabini-castellani\\\/\"]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/datacrazyworld.com\\\/index.php\\\/2023\\\/10\\\/08\\\/funciones-first_value-y-last_value\\\/#webpage\",\"url\":\"https:\\\/\\\/datacrazyworld.com\\\/index.php\\\/2023\\\/10\\\/08\\\/funciones-first_value-y-last_value\\\/\",\"name\":\"Funciones FIRST_VALUE y LAST_VALUE - Data Crazy World\",\"description\":\"\\u00bfConoces las funciones FIRST_VALUE y LAST_VALUE de T-SQL? Las conozcas o no, deber\\u00edas leer este peque\\u00f1o post para saber c\\u00f3mo funcionan y no errar en su uso.\",\"inLanguage\":\"es-ES\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/datacrazyworld.com\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/datacrazyworld.com\\\/index.php\\\/2023\\\/10\\\/08\\\/funciones-first_value-y-last_value\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/datacrazyworld.com\\\/index.php\\\/author\\\/tarabiquetevi\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/datacrazyworld.com\\\/index.php\\\/author\\\/tarabiquetevi\\\/#author\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/datacrazyworld.com\\\/wp-content\\\/uploads\\\/2023\\\/10\\\/TSQLPill.png\",\"@id\":\"https:\\\/\\\/datacrazyworld.com\\\/index.php\\\/2023\\\/10\\\/08\\\/funciones-first_value-y-last_value\\\/#mainImage\",\"width\":1200,\"height\":630,\"caption\":\"T-SQL Pill\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/datacrazyworld.com\\\/index.php\\\/2023\\\/10\\\/08\\\/funciones-first_value-y-last_value\\\/#mainImage\"},\"datePublished\":\"2023-10-08T19:00:00+00:00\",\"dateModified\":\"2023-10-08T18:50:51+00:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/datacrazyworld.com\\\/#website\",\"url\":\"https:\\\/\\\/datacrazyworld.com\\\/\",\"name\":\"DataCrazyWorld\",\"description\":\"SQL Server, PowerShell, Power BI, Power Platform,... Los datos, ese mundo tan interesante, variado, divertido y ... \\u00a1Loco!\",\"inLanguage\":\"es-ES\",\"publisher\":{\"@id\":\"https:\\\/\\\/datacrazyworld.com\\\/#person\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Funciones FIRST_VALUE y LAST_VALUE - Data Crazy World","description":"\u00bfConoces las funciones FIRST_VALUE y LAST_VALUE de T-SQL? Las conozcas o no, deber\u00edas leer este peque\u00f1o post para saber c\u00f3mo funcionan y no errar en su uso.","canonical_url":"https:\/\/datacrazyworld.com\/index.php\/2023\/10\/08\/funciones-first_value-y-last_value\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"BlogPosting","@id":"https:\/\/datacrazyworld.com\/index.php\/2023\/10\/08\/funciones-first_value-y-last_value\/#blogposting","name":"Funciones FIRST_VALUE y LAST_VALUE - Data Crazy World","headline":"Funciones FIRST_VALUE y LAST_VALUE","author":{"@id":"https:\/\/datacrazyworld.com\/index.php\/author\/tarabiquetevi\/#author"},"publisher":{"@id":"https:\/\/datacrazyworld.com\/#person"},"image":{"@type":"ImageObject","url":"https:\/\/datacrazyworld.com\/wp-content\/uploads\/2023\/10\/TSQLPill.png","width":1200,"height":630,"caption":"T-SQL Pill"},"datePublished":"2023-10-08T19:00:00+00:00","dateModified":"2023-10-08T18:50:51+00:00","inLanguage":"es-ES","mainEntityOfPage":{"@id":"https:\/\/datacrazyworld.com\/index.php\/2023\/10\/08\/funciones-first_value-y-last_value\/#webpage"},"isPartOf":{"@id":"https:\/\/datacrazyworld.com\/index.php\/2023\/10\/08\/funciones-first_value-y-last_value\/#webpage"},"articleSection":"SQL Server, tsql, sqlserver, tsql"},{"@type":"BreadcrumbList","@id":"https:\/\/datacrazyworld.com\/index.php\/2023\/10\/08\/funciones-first_value-y-last_value\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/datacrazyworld.com#listItem","position":1,"name":"Inicio","item":"https:\/\/datacrazyworld.com","nextItem":{"@type":"ListItem","@id":"https:\/\/datacrazyworld.com\/index.php\/category\/sqlserver\/#listItem","name":"SQL Server"}},{"@type":"ListItem","@id":"https:\/\/datacrazyworld.com\/index.php\/category\/sqlserver\/#listItem","position":2,"name":"SQL Server","item":"https:\/\/datacrazyworld.com\/index.php\/category\/sqlserver\/","nextItem":{"@type":"ListItem","@id":"https:\/\/datacrazyworld.com\/index.php\/category\/sqlserver\/tsql\/#listItem","name":"tsql"},"previousItem":{"@type":"ListItem","@id":"https:\/\/datacrazyworld.com#listItem","name":"Inicio"}},{"@type":"ListItem","@id":"https:\/\/datacrazyworld.com\/index.php\/category\/sqlserver\/tsql\/#listItem","position":3,"name":"tsql","item":"https:\/\/datacrazyworld.com\/index.php\/category\/sqlserver\/tsql\/","nextItem":{"@type":"ListItem","@id":"https:\/\/datacrazyworld.com\/index.php\/2023\/10\/08\/funciones-first_value-y-last_value\/#listItem","name":"Funciones FIRST_VALUE y LAST_VALUE"},"previousItem":{"@type":"ListItem","@id":"https:\/\/datacrazyworld.com\/index.php\/category\/sqlserver\/#listItem","name":"SQL Server"}},{"@type":"ListItem","@id":"https:\/\/datacrazyworld.com\/index.php\/2023\/10\/08\/funciones-first_value-y-last_value\/#listItem","position":4,"name":"Funciones FIRST_VALUE y LAST_VALUE","previousItem":{"@type":"ListItem","@id":"https:\/\/datacrazyworld.com\/index.php\/category\/sqlserver\/tsql\/#listItem","name":"tsql"}}]},{"@type":"Person","@id":"https:\/\/datacrazyworld.com\/#person","name":"Cristina Tarabini-Castellani Ciordia","image":{"@type":"ImageObject","@id":"https:\/\/datacrazyworld.com\/index.php\/2023\/10\/08\/funciones-first_value-y-last_value\/#personImage","url":"https:\/\/secure.gravatar.com\/avatar\/020df7a271c91fd52178caf747ffe0997d2f1113e00f58e77a2878622e27453f?s=96&d=mm&r=g","width":96,"height":96,"caption":"Cristina Tarabini-Castellani Ciordia"},"sameAs":["https:\/\/twitter.com\/DataCrazyWorld","https:\/\/www.linkedin.com\/in\/cristina-tarabini-castellani\/"]},{"@type":"Person","@id":"https:\/\/datacrazyworld.com\/index.php\/author\/tarabiquetevi\/#author","url":"https:\/\/datacrazyworld.com\/index.php\/author\/tarabiquetevi\/","name":"Cristina Tarabini-Castellani Ciordia","image":{"@type":"ImageObject","@id":"https:\/\/datacrazyworld.com\/index.php\/2023\/10\/08\/funciones-first_value-y-last_value\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/020df7a271c91fd52178caf747ffe0997d2f1113e00f58e77a2878622e27453f?s=96&d=mm&r=g","width":96,"height":96,"caption":"Cristina Tarabini-Castellani Ciordia"},"sameAs":["https:\/\/twitter.com\/DataCrazyWorld","https:\/\/www.linkedin.com\/in\/cristina-tarabini-castellani\/"]},{"@type":"WebPage","@id":"https:\/\/datacrazyworld.com\/index.php\/2023\/10\/08\/funciones-first_value-y-last_value\/#webpage","url":"https:\/\/datacrazyworld.com\/index.php\/2023\/10\/08\/funciones-first_value-y-last_value\/","name":"Funciones FIRST_VALUE y LAST_VALUE - Data Crazy World","description":"\u00bfConoces las funciones FIRST_VALUE y LAST_VALUE de T-SQL? Las conozcas o no, deber\u00edas leer este peque\u00f1o post para saber c\u00f3mo funcionan y no errar en su uso.","inLanguage":"es-ES","isPartOf":{"@id":"https:\/\/datacrazyworld.com\/#website"},"breadcrumb":{"@id":"https:\/\/datacrazyworld.com\/index.php\/2023\/10\/08\/funciones-first_value-y-last_value\/#breadcrumblist"},"author":{"@id":"https:\/\/datacrazyworld.com\/index.php\/author\/tarabiquetevi\/#author"},"creator":{"@id":"https:\/\/datacrazyworld.com\/index.php\/author\/tarabiquetevi\/#author"},"image":{"@type":"ImageObject","url":"https:\/\/datacrazyworld.com\/wp-content\/uploads\/2023\/10\/TSQLPill.png","@id":"https:\/\/datacrazyworld.com\/index.php\/2023\/10\/08\/funciones-first_value-y-last_value\/#mainImage","width":1200,"height":630,"caption":"T-SQL Pill"},"primaryImageOfPage":{"@id":"https:\/\/datacrazyworld.com\/index.php\/2023\/10\/08\/funciones-first_value-y-last_value\/#mainImage"},"datePublished":"2023-10-08T19:00:00+00:00","dateModified":"2023-10-08T18:50:51+00:00"},{"@type":"WebSite","@id":"https:\/\/datacrazyworld.com\/#website","url":"https:\/\/datacrazyworld.com\/","name":"DataCrazyWorld","description":"SQL Server, PowerShell, Power BI, Power Platform,... Los datos, ese mundo tan interesante, variado, divertido y ... \u00a1Loco!","inLanguage":"es-ES","publisher":{"@id":"https:\/\/datacrazyworld.com\/#person"}}]},"twitter:card":"summary_large_image","twitter:site":"@DataCrazyWorld","twitter:title":"Funciones FIRST_VALUE y LAST_VALUE - Data Crazy World","twitter:description":"\u00bfConoces las funciones FIRST_VALUE y LAST_VALUE de T-SQL? Las conozcas o no, deber\u00edas leer este peque\u00f1o post para saber c\u00f3mo funcionan y no errar en su uso.","twitter:creator":"@DataCrazyWorld","twitter:image":"https:\/\/datacrazyworld.com\/wp-content\/uploads\/2022\/12\/Color_Small.png","twitter:label1":"Escrito por","twitter:data1":"Cristina Tarabini-Castellani Ciordia","twitter:label2":"Tiempo de lectura estimado","twitter:data2":"3 minutos"},"aioseo_meta_data":{"post_id":"315","title":null,"description":null,"keywords":[],"keyphrases":{"focus":{"keyphrase":"","score":0,"analysis":{"keyphraseInTitle":{"score":0,"maxScore":9,"error":1}}},"additional":[]},"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":null,"og_article_tags":[],"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":"#post_title #separator_sa #site_title","twitter_description":"#post_excerpt","schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"BlogPosting","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":"-1","robots_max_videopreview":"-1","robots_max_imagepreview":"large","priority":null,"frequency":"default","local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2023-10-08 18:50:51","updated":"2025-06-04 03:39:31","seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/datacrazyworld.com\" title=\"Inicio\">Inicio<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/datacrazyworld.com\/index.php\/category\/sqlserver\/\" title=\"SQL Server\">SQL Server<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/datacrazyworld.com\/index.php\/category\/sqlserver\/tsql\/\" title=\"tsql\">tsql<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tFunciones FIRST_VALUE y LAST_VALUE\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Inicio","link":"https:\/\/datacrazyworld.com"},{"label":"SQL Server","link":"https:\/\/datacrazyworld.com\/index.php\/category\/sqlserver\/"},{"label":"tsql","link":"https:\/\/datacrazyworld.com\/index.php\/category\/sqlserver\/tsql\/"},{"label":"Funciones FIRST_VALUE y LAST_VALUE","link":"https:\/\/datacrazyworld.com\/index.php\/2023\/10\/08\/funciones-first_value-y-last_value\/"}],"_links":{"self":[{"href":"https:\/\/datacrazyworld.com\/index.php\/wp-json\/wp\/v2\/posts\/315","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/datacrazyworld.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/datacrazyworld.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/datacrazyworld.com\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/datacrazyworld.com\/index.php\/wp-json\/wp\/v2\/comments?post=315"}],"version-history":[{"count":1,"href":"https:\/\/datacrazyworld.com\/index.php\/wp-json\/wp\/v2\/posts\/315\/revisions"}],"predecessor-version":[{"id":317,"href":"https:\/\/datacrazyworld.com\/index.php\/wp-json\/wp\/v2\/posts\/315\/revisions\/317"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/datacrazyworld.com\/index.php\/wp-json\/wp\/v2\/media\/316"}],"wp:attachment":[{"href":"https:\/\/datacrazyworld.com\/index.php\/wp-json\/wp\/v2\/media?parent=315"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/datacrazyworld.com\/index.php\/wp-json\/wp\/v2\/categories?post=315"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/datacrazyworld.com\/index.php\/wp-json\/wp\/v2\/tags?post=315"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}