Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何对postgresql表进行排序,使连续值不匹配_Sql_Postgresql - Fatal编程技术网

如何对postgresql表进行排序,使连续值不匹配

如何对postgresql表进行排序,使连续值不匹配,sql,postgresql,Sql,Postgresql,如何编写一个postgresql查询或视图,以返回一个表,其中它的第一个结果在给定列中没有任何匹配的连续值。 例如,在此表中: +--------------------------+-------+----------------+--------+ | id | model | name | colour | +--------------------------+-------+----------------+-------

如何编写一个postgresql查询或视图,以返回一个表,其中它的第一个结果在给定列中没有任何匹配的连续值。 例如,在此表中:

+--------------------------+-------+----------------+--------+
|            id            | model |      name      | colour |
+--------------------------+-------+----------------+--------+
| 59663f188b06e815cae676f4 | ford  | amazing car    | red    |
| 59663f1487b60515ca614999 | ford  | great car      | pink   |
| 59663f230f519115cae6e089 | mini  | broken car     | blue   |
| 59663f1ce28a5315ca07262e | vw    | mystery mobile | blue   |
+--------------------------+-------+----------------+--------+
如果我选择型号或颜色,订单可能是:

+--------------------------+-------+----------------+--------+
|            id            | model |      name      | colour |
+--------------------------+-------+----------------+--------+
| 59663f188b06e815cae676f4 | ford  | amazing car    | red    |
| 59663f230f519115cae6e089 | mini  | broken car     | blue   |
| 59663f1487b60515ca614999 | ford  | great car      | pink   |
| 59663f1ce28a5315ca07262e | vw    | mystery mobile | blue   |
+--------------------------+-------+----------------+--------+

试试这个。如果数据具有多个重复值,则可能会起作用

Select 
   id
  ,model
  ,name
  ,colour
  ,row_number() over(partition by model) Rno
from Table
order by Rno

请不要使用不适用于您的问题的标记。这似乎是按模型对它们进行分组。我正在寻找洗牌他们,以便没有两个连续的模型匹配它不是分组。试着在你的桌子上执行,看不,你完全正确。那很有魅力。非常感谢你。