-1

I like to substring the second row 'text2'from the mysql table. Thanks!

    $sql = "select e.id, e.text1, e.text2, e.text3, count(r.id)     reportCount " . 
    "from employee e left join employee r on r.managerId = e.id " .
    "group by e.id order by e.text1, e.text2";

    try { ...
4

2 回答 2

0

在 select 语句中,您可以使用 case when 子句

select e.id, e.text1, 
    CASE 
       WHEN CHAR_LENGTH(e.text2) >= 30 THEN 
         SUBSTR(e.text2,0,30) 
       ELSE 
         e.text2 
      END as text2,
    ....

我只是没有测试就写了

于 2013-06-13T23:52:19.860 回答
0

Gökhan,感谢您的帮助。我已经解决了:

select e.id, e.text1, (SUBSTRING(e.text2,1,30)) AS 'text2' 

或带点:

select e.id, e.text1,
    CASE 
    WHEN CHAR_LENGTH(e.text2) > 30 THEN CONCAT(SUBSTRING(e.text2, 1, 30), '...')
    ELSE e.text2
    END AS text2 
于 2013-06-14T11:46:55.760 回答