i´m trying to insert some values in mysql but i get error code 1136, i verified and one of the values is auto-increment so i don't have to enter that one and the rest give a total of 18 which are exactly the total values i'm writting, could somebody help me?
This is the table im using:
FIELD TYPE NULL KEY DEFAULT EXTRA
id_display_detail int(11) NO PRI auto_increment
amount double NO
amount_lc double NO
exchange double NO
company varchar(10) NO
date datetime NO
description varchar(100) NO
document_number varchar(20) NO
document_type varchar(2) NO
posting_key varchar(3) NO
special_gl varchar(1) NO
status int(11) NO
voucher_number varchar(40) NO
year int(11) NO MUL
id_currency int(11) NO MUL
id_employee int(11) NO MUL
credit bit(1) YES
card_type varchar(45) NO
line_item int(11) YES
And this is my code:
INSERT INTO display_detail VALUES (300,300,0,'2001','2016-04-11',
'Downpayment ZM00080621','2000010802','ZP','29','R',0,
'GCCTEA 8062130',2016,1,1561,0,NULL,1);
Am i missing something?
and one of the values is auto-increment so i don't have to enter that one
That doesn't change the fact that the number of values in your VALUES clause has to match the number of columns.
You need to either specify NULL as the value for the auto_increment column - or specify a column list after INSERT first.
You missing the column name
(Because the id is automatic the values you provided don't math the number of column so must declare the column name)
INSERT INTO display_detail ( amount,
amount_lc ,
exchange ,
company ,
date ,
description ,
document_number,
document_type ,
posting_key ,
special_gl ,
status ,
voucher_number ,
year ,
id_currency ,
id_employee ,
credit ,
card_type ,
line_item ) VALUES (300,300,0,'2001','2016-04-11',
'Downpayment ZM00080621','2000010802','ZP','29','R',0,
'GCCTEA 8062130',2016,1,1561,0,NULL,1);
It appears that you aren't listing the columns in your INSERT statement. A MySQL query typically looks like this:
INSERT INTO table
(column1, column2, ... )
VALUES
(expression1, expression2, ... ),
(expression1, expression2, ... ),
...;
(Taken from: http://www.techonthenet.com/mysql/insert.php)
The final query would be something like this:
INSERT INTO display_detail
(amount, amount_lc, exchange, company, date, description,
document_number, document_type, posting_key,special_gl,status,voucher_number,year,
id_currency, id_employee, credit, card_type, line_item)
VALUES (300,300,0,'2001','2016-04-11',
'Downpayment ZM00080621','2000010802','ZP','29','R',0,
'GCCTEA 8062130',2016,1,1561,0,NULL,1);
Related
i was wondering how do i use the select query to Retrieve all offers of a listing.
Any tips or help to improve my codes is appreciated to! Thank you and have a nice day!
CREATE DATABASE IF NOT EXISTS `assignment_db`;
USE `assignment_db`;
CREATE TABLE USER_LIST(
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
userName VARCHAR(50) NOT NULL,
email varchar(100) NOT NULL,
registeredDate timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
);
create table listing_list(
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
itemName VARCHAR(50) NOT NULL,
itemDescription VARCHAR(254) NOT NULL,
price DECIMAL(4,2) NOT NULL,
fk_poster_id int references USER_LIST(id),
created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
);
create table offer_list(
id int(6) Unsigned auto_increment Primary key,
offer int,
fk_listing_id int references listing_list(id),
fk_offeror_id int references user_list(id),
created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
);
insert into user_list (userName, email) values ('John','johnnyboi#123.com');
insert into user_list (userName, email) values ('Tom','Tommyboi#123.com');
insert into listing_list (itemName,itemDescription, price) values ( 'Pen', 'A long delicate pen.',' 1.50 ');
insert into listing_list (itemName,itemDescription, price) values ( 'Pencil', 'A long delicate pencil.',' 0.50 ');
insert into offer_list (offer,fk_listing_id,fk_offeror_id) values ('200','2','3');
insert into offer_list (offer,fk_listing_id,fk_offeror_id) values ('200','1','1');
All offer listing for existing user :
select a.*,b.*,c.* from offer_list a
INNER JOIN (listing_list as b)
on a.fk_listing_id=b.Id
INNER JOIN (user_list as c)
on a.fk_offeror_id=c.Id
just all offer listing :
select a.*,b.* from listing_list b
INNER JOIN (offer_list as a)
on a.fk_listing_id=b.Id
just all offer listing 2nd way
select a.*,b.* from offer_list a
INNER JOIN (listing_list as b)
on a.fk_listing_id=b.Id
Check it here , i tested them in this FIDDLE
I was practicing the multi table on mysql. While creating the table, null data appeared on 'user table'. The user table should contain user_id(auto_increment). user_name should appear on user_info table which is from orders table.
create table orders(
primary key (order_id),
order_id int(11) not null auto_increment,
order_no varchar(100) default null,
user_name varchar(100) not null,
product_name varchar(100) not null,
order_status enum('CART', 'DRAFT', 'NEW', 'IN PROCESS', ' COMPLETED', 'FAILED' ) DEFAULT 'CART',
carete_date DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '注册时间');
There isn't any code which would insert anything into the "users" table, so I'm not sure why you would expect it to contain any data?
Your line
select distinct user_name from orders;
just after the create statement for the users table will simply display a list on screen. Perhaps you meant to write
insert into users (user_name) select distinct user_name from orders;
This will actually add some rows to the users table.
So I´ve looked trough the web in search for basic date help in sql and nobody seems to be able to help my codes goes like this
create table Hotel
(
id int not null primary key auto_increment,
Name varchar(255)
);
create table Gestur
(
id int not null primary key auto_increment,
nafn varchar(255),
heimili varchar(255),
simi char(7),
netfang varchar(255)
);
create table Bokun
(
id int not null primary key auto_increment,
ID_hotel_fk int references Hotel(id),
ID_gestur_fk int references Gestur(id),
dags_inn date null,
dags_ut date null,
tegund_herbergis char(1)
);
and I can´t seem to get this part right
insert into Bokun
(ID_gestur_fk,ID_hotel_fk,dags_inn,dags_ut,tegund_herbergis)
values
(1,3, 2015-10-25,2016-12-26,"1"),
(2,5, 2015-04-01, 2016-8-24,"3"),
(3,4, 2014-02-24, 2016-12-08,"1"),
(4,2, 2015-04-26, 2016-12-24,"2"),
(5,4, 2015-07-14, 2016-04-23,"1"),
(6,2, 2015-12-12, 2016-09-12,"3"),
(7,3, 2015-12-26, 2016-05-03,"2"),
(8,2, 2013-09-12, 2014-06-10,"1"),
(9,1, 2015-05-26, 2016-12-28,"1"),
(10,5, 2015-03-30, 2016-06-07,"4");
I only get the error
1292 - Incorrect date value: '1980' for column 'dags_inn' at row 1
You need to quote dates with ' and qoute "1" as '1':
insert into Bokun(ID_gestur_fk,ID_hotel_fk,dags_inn,dags_ut,tegund_herbergis)
values(1,3, '2015-10-25','2016-12-26','1');
2015-10-25 is treated as 1980 (aritmetic operation substraction)
SqlFiddleDemo
insert into Bokun
(ID_gestur_fk,ID_hotel_fk,dags_inn,dags_ut,tegund_herbergis)
values
(1,3, '2015-10-25','2016-12-26',"1"),
(2,5, '2015-04-01', '2016-8-24',"3"),
(3,4, '2014-02-24', '2016-12-08',"1"),
(4,2, '2015-04-26', '2016-12-24',"2"),
(5,4, '2015-07-14', '2016-04-23',"1"),
(6,2, '2015-12-12', '2016-09-12',"3"),
(7,3, '2015-12-26', '2016-05-03',"2"),
(8,2, '2013-09-12', '2014-06-10',"1"),
(9,1, '2015-05-26', '2016-12-28',"1"),
(10,5, '2015-03-30', '2016-06-07',"4");
you missed '(quotes).Thanks this helps..
Maybe the title is a little confusing but I will try to explain. I am trying to simulate the database of a telephone company. Among the tables I created, my interest is in these 3 tables.
CREATE TABLE `test`.`number` (
`MSISDN` BIGINT(10) NOT NULL COMMENT '',
`CUSTOMER_NUMBER` INT NOT NULL COMMENT '',
PRIMARY KEY (`MSISDN`) COMMENT ''
);
CREATE TABLE `test`.`bill_msisdn` (
`BILL_ID` INT NOT NULL COMMENT '',
`MONTHLY_FEE` DECIMAL(10 , 2 ) NOT NULL COMMENT '',
`CHARGES` DECIMAL(10 , 2 ) NULL DEFAULT 0 COMMENT '',
`TOTAL_BILL` DECIMAL(10 , 2 ) NOT NULL COMMENT '',
`MSISDN` VARCHAR(45) NOT NULL COMMENT '',
PRIMARY KEY (`BILL_ID`) COMMENT ''
);
CREATE TABLE `test`.`bill_customer_number` (
`BILL_ID_CUSTOMER` INT NOT NULL COMMENT '',
`CHARGE_DATE` DATE NOT NULL COMMENT '',
`TOTAL_BILL` DECIMAL(10 , 2 ) NOT NULL COMMENT '',
`CUSTOMER_NUMBER` INT NOT NULL COMMENT '',
PRIMARY KEY (`BILL_ID_CUSTOMER`) COMMENT ''
);
I filled these 3 tables with a little data to see if it works.
For the first table I wrote the following because I wanted to have 2 customers, the first with 2 numbers and the second with only one:
INSERT INTO number VALUES (6944747844,1234567);
INSERT INTO number VALUES (6944747845,1234567);
INSERT INTO number VALUES (6944747846,7654321);
For the second table I wrote:
INSERT INTO bill_msisdn VALUES (12345,10.50,0,MONTHLY_FEE+CHARGES,6944747844);
INSERT INTO bill_msisdn VALUES (12346,11.5,5.22,MONTHLY_FEE+CHARGES,6944747845);
INSERT INTO bill_msisdn VALUES (12347,3.10,9.02,MONTHLY_FEE+CHARGES,6944747846);
The MONTHLY_FEE+CHARGES i entered at TOTAL_BILL basicaly sums MONTHLY_FEE and CHARGES automatically.
What I do not know how to manage is at the third table (bill_customer_number)
I wrote:
INSERT INTO bill_customer_number VALUES (12345678,'2015-09-15',,1234567);
INSERT INTO bill_customer_number VALUES (12345679,'2015-09-13',,7654321);
leaving the TOTAL_BILL column, empty.
My question is if there is a way, to automatically calculate the TOTAL_BILL of each customer based on how many MSISDN's has.
For example customer 1234567 has two numbers ( 6944747844 and 6944747845). How can I fill automatically the column TOTAL_BILL of this line
INSERT INTO bill_customer_number VALUES (12345678,'2015-09-15',,1234567);
May be with help of subqueries?
INSERT INTO bill_customer_number VALUES (12345678,'2015-09-15',
( SELECT SUM(TOTAL_BILL) FROM bill_msisdn WHERE MSISDN = 1234567 )
,1234567);
I got this example to work with some help on here:
http://sqlfiddle.com/#!2/92e87/1
However, if I want to try and insert information for every child of the table, I cant seem to get it to work (using this code):
CREATE TABLE country (
id integer NOT NULL PRIMARY KEY AUTO_INCREMENT,
name varchar(255) NOT NULL
)
;
CREATE TABLE location (
id integer NOT NULL PRIMARY KEY AUTO_INCREMENT,
name varchar(255) NOT NULL,
coordinate varchar(255) NOT NULL,
country_id integer NOT NULL REFERENCES country (id)
)
;
CREATE TABLE item (
id integer NOT NULL PRIMARY KEY AUTO_INCREMENT,
title varchar(60) NOT NULL,
description varchar(900) NOT NULL,
date datetime NOT NULL,
source varchar(255) NOT NULL,
link varchar(255) NOT NULL,
location_id integer NOT NULL REFERENCES location (id)
)
;
Insert Into item (title) values ('Title');
Insert Into item (description) values ('Description');
Insert Into item (date) values ('1995-12-31T23:59:59Z');
Insert Into item (source) values ('Source');
Insert Into item (link) values ('Link');
Insert Into item (location_id) values ('1');
Is this the correct way of doing this? Secondly, it tells me "description" doesnt have a default value, but does it need one if I will always be putting information into it?
Thank you for any help you can give
Insert Into item (title, description, date, source, link, location_id)
values ('Title', 'Description','1995-12-31T23:59:59Z','source','Link',1);
Each insert acts as inserting a new record. hence you need to combine all data into one insert statement as given above.
The SQL asks for default value, because you have mentioned NOT NULL in the table definition which you have created.
For every insert, you will end up with a new row of data in the item table. I do not think this is what you want. Instead, do:
INSERT INTO item VALUES (NULL, [title], [description], [date], [source], [link], [location_id]);
Replace the items in [ and ] with the appropriate values.
You are being told that Description does not have a default value because in your INSERT statements that don't specify a value for that column, there is no default value that the database can fill in for that field.