Sql-Query: Hiding letters after space in the output
I've got a problem and hope you can help me find a solution.
Name Hours title
Name1 12 #1 (Text) - text - text
Name2 13 #1545 (text) - text - text
Name5 19 #33558 (text) - text - text
Name6 36 #54123 (text) – text
This is an extract from following query:
SELECT name AS Name, Sum((Unix_Timestamp(end)-Unix_Timestamp(start))/3600) AS Hours, title
FROM myTable
GROUP BY title;
Well, we've got a column with names, a column called Hours(how many hours did a name spend on sth.?) and a column called title(the title of sth.). The title of sth. includes #, a number and text.
开发者_如何学运维Is it possible to only get the number of the title? Like:
Name Hours title
Name1 12 1
Name2 13 1545
Name5 19 33558
Name6 36 54123
I'm stuck because the number length varies. I don't know whether there is a function just calling everything before the first space if the title contains a number.
I need it to compare the title with a csv-file.
Your help will be much appreciated. Soloco
EDIT There is always a space after #. Edit2:My bad, # has to be eliminated 2.
enter code hereTry this -
select substring(<columnname>,0,charindex(' ', <columnname>)) from <tableName>
In your case, the query will be -
select substring(title,0,charindex(' ', title)) from myTable
This works only if you have spaces and other text follwing your #<number>
USE LOCATE instead of Charindex for mysql -
http://www.overclock.net/web-coding/450373-mysql-query-help.html
Well, it's not a beautiful solution, but it fulfills my needs right now.
SELECT SUBSTRING(title,2,5)
If you see any other possibility please post.
精彩评论