0

我怎样才能在mysql中得到这个?我只想在重复中显示一次标题和 null

+-----------------------------+-------------+-------------+----------+
| title                       | created     | updated     | category |
+-----------------------------+---------------------+-----------------
| What If I Get Sick and Die? | 2008-12-30  | 2009-03-11  | angst    |
|                             | 2009-02-28  | NULL        | humor    |
|                             | 2009-03-02  | NULL        | advice   |
|                             | 2009-03-17  | NULL        | humor    |
| The Size of Our Galaxy      | 2009-04-03  | NULL        | science  |
|                             | 2009-03-02  | NULL        | advice   |
|                             | 2009-03-17  | NULL        | humor    |
|                             | 2009-04-03  | NULL        | science  |
+-----------------------------+---------------------+-----------------
4

1 回答 1

0

您可以使用以下查询来实现此目的:

SELECT CASE WHEN
(
    SELECT t1.id 
    FROM tablename t1 
    WHERE t1.title = t.title LIMIT 1
) = t.id THEN t.title
ELSE null END AS title
,t.created
,t.updated
,t.category
FROM tablename t
于 2012-12-06T22:01:10.183 回答