Mysql:如何从数据库列中选择不同的值

标签 mysql distinct

我的目标是从存在大量重复值的“EmbedImgDimension”列中选择值。

我使用了以下查询

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”列中选择唯一值。我们将不胜感激任何帮助。

谢谢。

最佳答案

  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——当你想要维度唯一性时,你不能同时得到所有不同的视频标识符,明白我的意思吗?

关于Mysql:如何从数据库列中选择不同的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3413542/

相关文章:

php - 使用 fat-free-framework 获取最新插入的自动递增记录 ID

MySQL 创建具有可变列名的 View

MySQL 在字符串中查找字符串的结束位置

mysql - 我有两个名为 created_at 和 updated_at(timestamps) 的字段,我想在我的 where 子句中的这些日期之间进行搜索

c# - 在 .NET 中有效地合并字符串数组,保持不同的值

java - 无法在一个范围内找到 DISTINCT 素因子的 NUMBER

php - 使用 DISTINCT 和 UNION 在 SQL 查询中获取字段名称

node.js - Mongoose 可以为我提供某个领域的所有不同值(value)吗?

mysql - 如何将一个表拆分为多个表

sorting - Elasticsearch:如何获取按匹配分数排序的字段的最高唯一值?