<?xml version='1.0' encoding="utf-8"?>
      <rss version='2.0'>
      <channel>
      <title>Форум на Исходниках.RU</title>
      <link>https://forum.sources.ru</link>
      <description>Форум на Исходниках.RU</description>
      <generator>Форум на Исходниках.RU</generator>
  	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=410067&amp;view=findpost&amp;p=3697835</guid>
        <pubDate>Wed, 14 Dec 2016 16:41:30 +0000</pubDate>
        <title>Перестроение пользовательской сортировки</title>
        <link>https://forum.sources.ru/index.php?showtopic=410067&amp;view=findpost&amp;p=3697835</link>
        <description><![CDATA[Akina: Запрос для понимания сути происходящего:<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">SET @from=3;</div><div class="code_line">SET @to=5;</div><div class="code_line">SELECT *, SortKey + CASE SortKey</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WHEN @from THEN @to-@from</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ELSE &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sign(@from-@to)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;END</div><div class="code_line">FROM test</div><div class="code_line">-- WHERE SortKey BETWEEN LEAST(@from,@to) AND GREATEST(@from,@to)</div><div class="code_line">-- ORDER BY id</div><div class="code_line">;</div></ol></div></div></div></div><script>preloadCodeButtons('1');</script><br>
Повторять, произвольно меняя значения переменных. <br>
<br>
PS. Предполагается, что у SortKey нумерация непрерывная, а @from и @to входят в список имеющихся в таблице значений.]]></description>
        <author>Akina</author>
        <category>Базы данных: SQL</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=410067&amp;view=findpost&amp;p=3697831</guid>
        <pubDate>Wed, 14 Dec 2016 16:15:08 +0000</pubDate>
        <title>Перестроение пользовательской сортировки</title>
        <link>https://forum.sources.ru/index.php?showtopic=410067&amp;view=findpost&amp;p=3697831</link>
        <description><![CDATA[JoeUser: Гуд, благодарю&#33;  :)]]></description>
        <author>JoeUser</author>
        <category>Базы данных: SQL</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=410067&amp;view=findpost&amp;p=3697830</guid>
        <pubDate>Wed, 14 Dec 2016 16:13:21 +0000</pubDate>
        <title>Перестроение пользовательской сортировки</title>
        <link>https://forum.sources.ru/index.php?showtopic=410067&amp;view=findpost&amp;p=3697830</link>
        <description><![CDATA[Akina: Поразбирайся. Все вопросы сами отпадут.]]></description>
        <author>Akina</author>
        <category>Базы данных: SQL</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=410067&amp;view=findpost&amp;p=3697829</guid>
        <pubDate>Wed, 14 Dec 2016 16:11:59 +0000</pubDate>
        <title>Перестроение пользовательской сортировки</title>
        <link>https://forum.sources.ru/index.php?showtopic=410067&amp;view=findpost&amp;p=3697829</link>
        <description><![CDATA[JoeUser: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=410067&view=findpost&p=3697784'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Akina &#064; <time class="tag-quote__quoted-time" datetime="2016-12-14T12:32:20+00:00">14.12.16, 12:32</time></span><div class='quote '>Для MySQL:</div></div><br>
Пасиб, поразбираюсь&#33; <br>
А это любой перенос сработает, я имею ввиду вниз, вврерх, в первую, в последнюю позиции?]]></description>
        <author>JoeUser</author>
        <category>Базы данных: SQL</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=410067&amp;view=findpost&amp;p=3697784</guid>
        <pubDate>Wed, 14 Dec 2016 12:32:20 +0000</pubDate>
        <title>Перестроение пользовательской сортировки</title>
        <link>https://forum.sources.ru/index.php?showtopic=410067&amp;view=findpost&amp;p=3697784</link>
        <description><![CDATA[Akina: Для MySQL:<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">UPDATE test</div><div class="code_line">SET SortKey = SortKey + CASE SortKey </div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WHEN @from THEN @to-@from</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ELSE &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sign(@from-@to)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;END</div><div class="code_line">WHERE SortKey BETWEEN LEAST(@from,@to) AND GREATEST(@from,@to);</div></ol></div></div></div></div>]]></description>
        <author>Akina</author>
        <category>Базы данных: SQL</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=410067&amp;view=findpost&amp;p=3697773</guid>
        <pubDate>Wed, 14 Dec 2016 11:58:48 +0000</pubDate>
        <title>Перестроение пользовательской сортировки</title>
        <link>https://forum.sources.ru/index.php?showtopic=410067&amp;view=findpost&amp;p=3697773</link>
        <description><![CDATA[JoeUser: <span class='tag-size' data-value='14' style='font-size:14pt;'><strong class='tag-b'>Интересует способ перестроения пользовательской сортировки</strong></span><br>
<br>
Исходные данные (упрощенно):<br>
<br>
1) Таблица &quot;Рубрикаторы&quot;<br>
<br>
<span class='tag-size' data-value='10' style='font-size:10pt;'><pre>
  Id - SERIAL
Name - VARCHAR
</pre></span><br>
2) Таблица &quot;Сортировки&quot;<br>
<br>
<span class='tag-size' data-value='10' style='font-size:10pt;'><pre>
  RubId - INTEGER
SortKey - INTEGER
</pre></span><br>
Вторая таблица нужна для того, чтобы предполагаемый пользователь мог сохранять нужный ему порядок сортировки &quot;рубрикаторов&quot;. <br>
Изначально Id=RubId=SortKey<br>
<br>
Вопрос: каким запросом(ами) произвести модификацию таблицы &quot;Сортировки&quot;, по образцу:<br>
<br>
<span class='tag-size' data-value='10' style='font-size:10pt;'><pre>
RubId | KeySort
---------------
  1   |   1
  2   |   2
  3   |   3 &lt;─┐
  4   |   4   │
  5   |   5   │
  6   |   6   │
  7   |   7 ──┘
  8   |   8  
  9   |   9
---------------
</pre></span><br>
Нужно перенести 7-ю позицию на 3-е место:<br>
<br>
<span class='tag-size' data-value='10' style='font-size:10pt;'><pre>
RubId | KeySort
---------------
  1   |   1
  2   |   2
  3   |   4
  4   |   5
  5   |   6
  6   |   7
  7   |   3
  8   |   8
  9   |   9
---------------
</pre></span>]]></description>
        <author>JoeUser</author>
        <category>Базы данных: SQL</category>
      </item>
	
      </channel>
      </rss>
	