MySQL Concat (Length) with Alias

时间:2015-07-28 16:06:08

标签: mysql alias concat

I have been formatting a select query into one giant string with set lengths:

SELECT DISTINCT 
    CONCAT(CONCAT(ulname,SPACE(15-LENGTH(ulname))))
FROM users WHERE ulname = 'Test'

But is it possible to do the same with a blank alias? If I were to do

Select '' AS CustomerID 

I'm not exactly sure how I would set the spacing then. Would it be something like

CONCAT('' AS CustomerID, SPACE(10 - LENGTH(CustomerID)))?

1 个答案:

答案 0 :(得分:0)

Maybe you are looking for something like this:

SELECT DISTINCT 
    LEFT(CONCAT(ulname,SPACE(15)),15)
FROM test 
WHERE ulname = 'test';