Questions tagged as 'sql'

1
answer

See if two dates overlap

I have to make a query that consists of checking if the start date that they insert me and the end date that they insert me is not included in another existing article, that is: Artículo { Id:1 Nombre:'mesa' F_ini: 1/7/2018 F_fin : 31/7/2018 }...
asked by 23.07.2018 / 09:47
1
answer

Find dates closer to a given date

Good morning. I try to recover, based on a group of dates given by a user, the dates of a table that most closely match the dates given. The test data and tables are like this: create table PAC_ID_T ( IdPaciente int, NHC varchar (10)...
asked by 23.05.2018 / 19:18
1
answer

FK from the same table, show data

Could someone help me with the sentence? I would like the nIdePadre = '1' to show in another column the description of nIdeArea = '1' , and more or less it looks like this: nIdarea --- nIdePadre --- nIdeEmpresa --- VDesc...
asked by 22.05.2018 / 19:33
2
answers

Laravel Bring data of the model grouped by months

Hello, I have the following table in the DB Fruta id | name | precio | fecha_compra I would like to bring the total price of all purchased fruits grouped by months using eloquent or querybuuilder the result that is but is the following...
asked by 27.06.2018 / 23:06
1
answer

Convert SQL query to Eloquent Laravel 5.6

I have the following SQL query to get grouped and ordered by months the sum of prices of three products, which makes no problem SELECT name, SUM(precio) AS total, mes FROM productos GROUP BY mes ORDER BY mes DESC; The result I get is...
asked by 28.06.2018 / 02:49
1
answer

Error dividing into a function

DELIMITER $$ DROP FUNCTION IF EXISTS amountInP $$ CREATE FUNCTION amountInP (euros INTEGER) RETURNS INTEGER BEGIN SELECT amountInP.euros/166.386 AS 'Pessetes' ; END $$ DELIMITER ; SELECT amountInP(2000); I'm doing this function and you're giv...
asked by 09.05.2018 / 13:11
1
answer

Error subtracting two dates

I am doing this function to subtract the date of an unpaid fine, from that date to the current date. But I get an error DELIMITER $$ DROP FUNCTION IF EXISTS finesNotPayed $$ CREATE FUNCTION finesNotPayed (fineDate INTEGER) RETURNS INTEGER BEGI...
asked by 09.05.2018 / 22:39
2
answers

foreign wrongly entered

I have been with this error for hours: Error Code: 1005. Can not create table prueba . montaje (errno: 150 "Foreign key constraint is incorrectly formed") Can someone tell me what I have wrong with my code? CREATE TABLE Mo...
asked by 14.10.2018 / 04:01
1
answer

How to update a field Id

I have a migrated information to a table I need in that field to create a number that starts from the 16th and ends until the last record that is in that column.     
asked by 16.10.2018 / 05:58
1
answer

Relationships in BD

Hi, I have a question about a relationship and I would like to know if this is a wrong way or is there a better way? These are sample tables, suppose that a post is created and this post can have many comments and can also have many responses, b...
asked by 11.07.2018 / 17:07