Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I made a table and I want to select certain data from the table using select statements.
I want to see all the book titles that were published in May.
How can I go about doing this?
Here is the table
CREATE TABLE titles
(
title_id CHAR(3) NOT NULL,
title_name VARCHAR(40) NOT NULL,
type VARCHAR(10) ,
pub_id CHAR(3) NOT NULL,
pages INTEGER ,
price DECIMAL(5,2) ,
sales INTEGER ,
pubdate DATE ,
contract SMALLINT NOT NULL,
CONSTRAINT pk_titles PRIMARY KEY (title_id)
)ENGINE = InnoDB;
I tried this:
SELECT * FROM titles
WHERE pubdate LIKE '%%%%-05-%%';
It displays the whole column, how can I get it to only display the books title?
Try this:
SELECT title_name FROM titles WHERE MONTH(pubdate) = '5'
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 26 days ago.
Improve this question
I want to create a table.
I'm having long and hard time about naming columns.
If there are 3 columns having same characteristics.
ex) tag_1, tag_2, tag_3
->
CREATE TABLE BOARD (
BOARD_ID bigint not null
primary key,
TAG_1 varchar(10) null,
TAG_2 varchar(10) null,
TAG_3 varchar(10) null
)
Is it a best practice to naming like examples above?
It should be something like this:
CREATE TABLE BOARDS
(
BOARD_ID BIGINT
,name ...
,description ...
);
CREATE TABLE TAGS
(
TAG_ID INT
,TAG VARCHAR(10)
);
CREATE TABLE BOARDSTAGS
(
BOARD_ID BIGINT
,TAG_ID INT
);
You have one table for describing board properties and one of tag properties. Some of the tags can be shared across many boards. So, we need third table for telling which board, which tags has.
In this case, when you need additional tags, you do not need to add new column in the board table.
Nothing wrong with your notation. However, as your columns look really identical, you might wanna take a look into normalizing them. It might make sense in many cases and it will keep your schema cleaner.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
CREATE TABLE Employee (
Code int NOT NULL,
Last_Name varchar(25) NOT NULL,
First_Name varchar(25),
Age int(2),
City varchar(30) DEFAULT 'KAJI'
);
If I am following you correctly then you are talking about the following line:
...
City varchar(30) DEFAULT 'KAJI'
...
It is not allowed to provide multiple default values for a single column.
If multiple default values are allowed then which value will be used as the default(How DB will decide it)? That's why it is very obvious that there should be only one default value. I Hope, I am clear.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I have following Statment in MySQL and become every time this error(Screenshot):
CREATE TABLE orderstatus
(
OStatusID int NOT null PRIMARY KEY AUTO_INCREMENT,
OStatus varchar(30) null
(
I dont know why I become this error
Can you help me, please?
enter image description here
the close bracket is wrong, it should be ')'
try this
CREATE TABLE orderstatus
(
OStatusID int NOT null PRIMARY KEY AUTO_INCREMENT,
OStatus varchar(30) null
)
Below is right code Tested Successfully..
CREATE TABLE orderstatus
(
OStatusID int NOT null PRIMARY KEY AUTO_INCREMENT,
OStatus varchar(30) null
)[enter image description here][1]
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I'm working on a database for my database class.
I have been trying to change the INT from SUBJECT_ID to VARCHAR.
This is the code I have been using but it keeps giving me errors:
ALTER TABLE COURSE
ALTER COLUMN SUBJECT_ID VARCHAR(11);
I also tried this:
SELECT CONVERT(VARCHAR(11),SUBJECT_ID) FROM COURSE;
and this is the table I'm working with:
CREATE TABLE COURSE
(COURSE_ID INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
SUBJECT_ID INT(11) NOT NULL,
COURSE_GRADE_LEVEL CHAR(2) NOT NULL,
FAC_ID INT NOT NULL,
FOREIGN KEY(FAC_ID) REFERENCES FACULTY(FAC_ID));
Any suggestions will be appreciated. Thanks.
Try:
ALTER TABLE COURSE MODIFY SUBJECT_ID VARCHAR(11);
select cast(subject_id as varchar(11)) as subject_id_str from course
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a db table which stores votes made against articles. I would like to query the table to find, within the last 30 days, the articles which on average have received the best overall votes.
I'm looking for some advice on how I should do this, I am guessing I can either do this with PHP or MYSQL. Although I have a better grasp of PHP I would imagine that using MYSQL to get my result is better practice.
CREATE TABLE IF NOT EXISTS `ratings` (
`id` int(11) NOT NULL,
`article_id` int(11) NOT NULL AUTO_INCREMENT,
`rating` int(11) NOT NULL,
`ip` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
`timestamp` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=2054 ;
Is there a way to sum and find an average given this table structure.
Thnak you.
Alan.
There is a function AVG() in MySQL. So
SELECT AVG(rating)
FROM ratings
WHERE article_id = 1
Will give the average rating of the articles with article_id 1.
There's also a SUM() function in MySQL. So
SELECT SUM(rating)
FROM ratings
WHERE article_id = 1
Will give the sum of all ratings of the articles with article_id 1.