Solved

sql select time convert to  time to   a   b mysql

Posted on 2016-11-13
4
77 Views
Last Modified: 2016-11-13
worktime  
09:01
09.00
09.30
09.35



how can I  select  from 09:00   to   09:29 become a  
and  09:30 to 09:35  become a

result
worktime         timenote
09:01                a
09.00                a
09.30                b
09.35                b

remark worktime colum is timestampFormat

SELECT WORKTIME  ,  fUNCTION( WORKTIME)      ETC
0
Comment
Question by:teera
  • 2
  • 2
4 Comments
 
LVL 28

Expert Comment

by:Pawan Kumar
ID: 41885834
Your question is not very clear ? Can you state your question and the expected output clearly?
0
 

Author Comment

by:teera
ID: 41885860
Table have only one column  but I want out put 2 column

original table

worktime  
09:01
09.00
09.30
09.35

out put table

worktime         timenote
09:01                a
09.00                a
09.30                b
09.35                b
0
 
LVL 28

Accepted Solution

by:
Pawan Kumar earned 500 total points
ID: 41885885
try..

CREATE TABLE `Examplex`
(
 `id`                  INTEGER(10),      
 `created_at`          DATETIME,
  PRIMARY KEY (id)
);


INSERT INTO `Examplex` (`id`,`created_at` ) VALUES (1,'2016-11-14 09:17:47.473')

INSERT INTO `Examplex` (`id`,`created_at` ) VALUES (2,'2016-11-14 09:17:47.473')

INSERT INTO `Examplex` (`id`,`created_at` ) VALUES (3,'2016-11-14 09:30:47.473')

INSERT INTO `Examplex` (`id`,`created_at` ) VALUES (4,'2016-11-14 09:31:47.473')

INSERT INTO `Examplex` (`id`,`created_at` ) VALUES (5,'2016-11-14 09:35:47.473')



SELECT `created_at` as WorkTime , 
	CASE 
		WHEN CAST(`created_at` AS TIME) >= '9:00' AND CAST(`created_at` AS TIME) <= '9:30' THEN 'a'
        ELSE 'b'
    END AS timeNote
FROM `Examplex`

Open in new window

0
 

Author Closing Comment

by:teera
ID: 41885914
Thank you
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many developers have database experience, but are new to PostgreSQL. It has some truly inspiring capabilities. I have several years' experience with Microsoft's SQL Server. When I began working with MySQL, I wanted a quick-reference to MySQL (htt…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Steps to create a PostgreSQL RDS instance in the Amazon cloud. We will cover some of the default settings and show how to connect to the instance once it is up and running.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question