2010-08-05 110 views
0

我的目标是从存在大量重复值的“EmbedImgDimension”列中选择值。Mysql:如何从数据库列中选择不同的值

我用下面的查询

select 
    distinct EmbedImgId, 
    VideoID, 
    EmbedImgHeight, 
    EmbedImgWidth, 
    EmbedImgFileName, 
    concat(embedimgwidth,' x ',embedimgheight) as EmbedImgDimension 
    from embedimages 
    inner join Video on Video.schoolid=#Value# 
    where embedimages.isdeleted=0 order by embedimages.embedimgwidth asc; 

笏修改应该怎么做在此查询,以便从“EmbedImgDimension” column.Any帮助将十分赞赏选择唯一值。

谢谢。

回答

3
select 
    distinct concat(embedimgwidth,' x ',embedimgheight) as EmbedImgDimension 
    from embedimages 
    inner join Video on Video.schoolid=#Value# 
    where embedimages.isdeleted=0 order by embedimages.embedimgwidth asc; 

更新

说你也想不同的视频ID是一个逻辑问题。你想得到一个结果,每个维度只出现一次,对吗?那么,你怎么能期望获得所有不同的videoID结果呢?想象你有

videoid dimension 
     1  1x1 
     2  1x1 
     3  2x2 
     4  2x2 

也许你可以告诉我你想得到哪个结果。 但是你要么得到1x1和2x2,要么你会得到1,2,3,4 - 当你想要维度唯一性的时候,你不能也得到所有不同的视频文件,看看我的意思?

+0

如果你想获得不同的值,你必须删除非独特的值(如video_ids)。你现在的方式,数据库试图找到video_id,EmbedImgId等独特的组合(这可能是独特的,所以你不会得到任何分组) – Nicolas78 2010-08-05 09:57:14

+0

@ nicolas78:谢谢朋友......但我也需要实施 选择 不同EmbedImgId, VideoID的, EmbedImgHeight, EmbedImgWidth, EmbedImgFileName我的查询......所以笏可以做... – GethuJohn 2010-08-05 10:02:27

+0

检查我的更新。我认为你想在逻辑上不可能,但也许你可以进一步详细说明 – Nicolas78 2010-08-05 10:07:19

1

EmbedImgDimension列中使用distinct关键字。

+0

你能向我解释一下在当前查询 – GethuJohn 2010-08-05 09:53:54

+0

中必须进行的修改,例如: 'select distinct(concat(“test”,col_name))from table_name' – thelost 2010-08-05 09:56:59

+0

谢谢..让我试试 – GethuJohn 2010-08-05 10:04:57