Find Jobs
Hire Freelancers

One MS SQL Query needed

€8-30 EUR

Terminado
Publicado hace más de 5 años

€8-30 EUR

Pagado a la entrega
I have MS SQL table which I filter by MyAction, Type1, Type2, Type3, MyXml and I group it by RecordDate and need to get aggregated values (as specified bellow) together with first price (from first date in sequence) and last price (from last date in sequence). Table specification and my current query is bellow. My query does not return ok FirstPrice nad LastPrice - it returns all the same values for all days (they should be different). I know why - because these subqueries are written without grouping by days. Need you to create new query and make it fastest as possible (I use MS SQL 2016 SP1) and this table has a lot of records. CREATE TABLE MyTable ( Id int IDENTITY(1,1) NOT NULL, RecordDate datetime NOT NULL, MyAction varchar(20) NOT NULL, Price decimal(18, 4) NOT NULL, Volume decimal(8, 2) NOT NULL, Type1 varchar(20) NOT NULL, Type2 varchar(20) NOT NULL, Type3 varchar(20) NOT NULL, MyXml xml NOT NULL PRIMARY KEY CLUSTERED ( Id ASC ) ) SELECT CONVERT(date, RecordDate) as GroupedDate, MIN(Price) as LowPrice, MAX(Price) as HighPrice, SUM(Price * Volume) / SUM(Volume) as AveragePrice, SUM(Volume) as Volume, (SELECT TOP 1 Price FROM MyTable WHERE MyAction <> 'Remove' AND CAST(MyXml as nvarchar(max)) LIKE '%SeqSpan="Single"%' AND Type1 = 10001126 AND Type2 = 10000104 AND Type3 = 175 ORDER BY RecordDate ASC) AS FirstPrice, (SELECT TOP 1 Price FROM MyTable WHERE MyAction <> 'Remove' AND CAST(MyXml as nvarchar(max)) LIKE '%SeqSpan="Single"%' AND Type1 = 10001126 AND Type2 = 10000104 AND Type3 = 175 ORDER BY RecordDate DESC) AS LastPrice FROM MyTable WHERE MyAction <> 'Remove' AND CAST(MyXml as nvarchar(max)) LIKE '%SeqSpan="Single"%' AND Type1 = 10001126 AND Type2 = 10000104 AND Type3 = 175 GROUP BY CONVERT(date, RecordDate) ORDER BY GroupedDate
ID del proyecto: 17650559

Información sobre el proyecto

10 propuestas
Proyecto remoto
Activo hace 6 años

¿Buscas ganar dinero?

Beneficios de presentar ofertas en Freelancer

Fija tu plazo y presupuesto
Cobra por tu trabajo
Describe tu propuesta
Es gratis registrarse y presentar ofertas en los trabajos
Adjudicado a:
Avatar del usuario
Low bid bc of very strong knowledge of SQL Queries, Views, Sps, Triggers, UDFs, Static and Dynamic Queries, Can complete shortly
€22 EUR en 1 día
4,4 (3 comentarios)
1,7
1,7
10 freelancers están ofertando un promedio de €20 EUR por este trabajo
Avatar del usuario
Hi, I have 9 years experience in development and deployment that includes SQL Server, SSRS, SSIS and .NET. Involved in SQL Server activities like Installing, Migrations, Table Partitioning, Configuring maintenance jobs, Optimizing etc. I have expertise in writing complex queries with proper joins and index selection. Involved in designing databases, Indexing Strategies, table partitioning, writing Stored Procedures, Triggers, functions and views. I have delivered highly successful projects in ASP.NET, C#/VB.NET Win-Forms, EF with complex logic in SQL Server Stored Procedures. Thanks
€29 EUR en 1 día
4,9 (54 comentarios)
6,7
6,7
Avatar del usuario
Dear Employer, This is not a bid that I want to get - just a couple of observations based on your design. Since your are striving for speed, and I do not really know what is going on with your application, but here are some things you could do if application allows. XML is very speed-inefficient data type in SQL server since it invokes one more pre-processor - you need to verify the validity of XML, then store some very large amount of data. If you can - normalize data at application level, if you can't and want to serialize - store XML as text - and process it in the middle layer of your application. Type 1,2,and 3 seem to be digital - why do you store them as strings? Besides, usually, you would normalize with typeId into its own table have zero to three corresponding records in MyTable (which should better have RecordLog name) table. MyAction should have its own table with ids as well. If you store it this way, your query will simplify significantly, your searches will be with integers or big integers (4-8 bytes instead of 20) which are better sequentialized and two extra joins will not kill you - to the contrary you will ]index easier and SQL server will search 3 records for types instead of millions in the log table. My 2 cents, enjoy. If you want - pay.
€8 EUR en 1 día
5,0 (5 comentarios)
4,9
4,9
Avatar del usuario
Hi I am Mysql expert lets start. Thank you. _
€25 EUR en 1 día
4,5 (30 comentarios)
4,6
4,6
Avatar del usuario
I have more than 3 years of exerience as sql devloper and mostly working sales report for us based comany. I am dealing with these kind of queries for daily basis. It will take less than 1Hr for me to solve this query. You can reach out me on +91 9975111392 or skype me on saudagarljadhav Thanks
€15 EUR en 1 día
0,0 (0 comentarios)
0,0
0,0

Sobre este cliente

Bandera de SLOVENIA
Ljubljana, Slovenia
5,0
1
Forma de pago verificada
Miembro desde ago 27, 2018

Verificación del cliente

¡Gracias! Te hemos enviado un enlace para reclamar tu crédito gratuito.
Algo salió mal al enviar tu correo electrónico. Por favor, intenta de nuevo.
Usuarios registrados Total de empleos publicados
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
Cargando visualización previa
Permiso concedido para Geolocalización.
Tu sesión de acceso ha expirado y has sido desconectado. Por favor, inica sesión nuevamente.