如何在一列中获得不同的多列行
How to Get Distinct More than one Column Rows in one Column
我想在一列中包含 5 列的行,在该列中包含唯一的行。
SELECT DISTINCT date,accept_date, question_date,success_date
FROM user_presentation;
我得到的行是:
date accept_date question_date success_date
2018-12-07 2018-11-23 2018-12-21 2019-01-04
2018-12-21 2018-12-07 2019-01-04 2019-01-18
2019-01-04 2018-12-21 2019-01-18 2019-02-01
2019-01-18 2019-01-04 2019-02-01 2019-02-15
2019-02-01 2019-01-18 2019-02-15 2019-03-01
我想要一列中的所有行,但只有唯一值
SELECT DISTINCT val
FROM
( SELECT 'date' date_type
, date val
FROM user_presentation
UNION
SELECT 'accept_date'
, accept_date
FROM user_presentation
UNION
SELECT 'question_date'
, question_date
FROM user_presentation
UNION
SELECT 'success_date'
, success_date
FROM user_presentation
) normalized;
我不是 100% 确定你想要什么,举个例子会很清楚。如果@Strawberry 在正确的轨道上,那么它可以大大简化,因为 UNION 将始终删除重复项。
简化版为:
SELECT date val FROM user_presentation
UNION
SELECT accept_date FROM user_presentation
UNION
SELECT question_date FROM user_presentation
UNION
SELECT success_date FROM user_presentation
我想在一列中包含 5 列的行,在该列中包含唯一的行。
SELECT DISTINCT date,accept_date, question_date,success_date
FROM user_presentation;
我得到的行是:
date accept_date question_date success_date
2018-12-07 2018-11-23 2018-12-21 2019-01-04
2018-12-21 2018-12-07 2019-01-04 2019-01-18
2019-01-04 2018-12-21 2019-01-18 2019-02-01
2019-01-18 2019-01-04 2019-02-01 2019-02-15
2019-02-01 2019-01-18 2019-02-15 2019-03-01
我想要一列中的所有行,但只有唯一值
SELECT DISTINCT val
FROM
( SELECT 'date' date_type
, date val
FROM user_presentation
UNION
SELECT 'accept_date'
, accept_date
FROM user_presentation
UNION
SELECT 'question_date'
, question_date
FROM user_presentation
UNION
SELECT 'success_date'
, success_date
FROM user_presentation
) normalized;
我不是 100% 确定你想要什么,举个例子会很清楚。如果@Strawberry 在正确的轨道上,那么它可以大大简化,因为 UNION 将始终删除重复项。
简化版为:
SELECT date val FROM user_presentation
UNION
SELECT accept_date FROM user_presentation
UNION
SELECT question_date FROM user_presentation
UNION
SELECT success_date FROM user_presentation