尝试使用mysql在第一个字母上开始大写

时间:2011-07-20 10:46:08

标签: mysql sql mysql-workbench uppercase

我有

              Visit table 
                 Visit_Id
                 Visit_Date values(09-09-2011)
                 Visit_status values like (accepted , refused)
                member_Id

我这样做是为了获得访问次数 通过使用以下查询

SELECT visit_Status as Status, COUNT('x') AS Visits
                              FROM visits
                              WHERE visit_Date BETWEEN '2011-06-20' AND '2011-07-20'
                              GROUP BY visit_Status

它正在给出这样的结果

                Status          Visits
                accepted         2
                refused          4

我可以得到像这样的结果

                Status          Visits

                Accepted         2
                Refused          4


      with upper case letter on first letter of status i mean like this ( Accepted , Refused) instead of this one  (accepted , refused)

我正在使用mysql工作台

3 个答案:

答案 0 :(得分:6)

您可以使用SUBSTRINGUPPER

select CONCAT(UPPER(SUBSTRING(visit_Status, 1, 1)), 
      LOWER(SUBSTRING(visit_Status FROM 2))) as Status ......

答案 1 :(得分:2)

这将做你想要的:

SELECT CONCAT(UPPER(SUBSTRING(Visit_status, 1, 1)), LOWER(SUBSTRING(Visit_status FROM 2))) AS Status COUNT('x') AS Visits
       FROM visits
      WHERE visit_Date BETWEEN '2011-06-20' AND '2011-07-20'
      GROUP BY visit_Status

答案 2 :(得分:1)

SELECT CONCAT(UPPER(SUBSTRING(Visit_status, 1, 1)), SUBSTRING(Visit_status FROM 2)) as Status, COUNT('x') AS Visits
FROM visits
WHERE visit_Date BETWEEN '2011-06-20' AND '2011-07-20'
GROUP BY visit_Status