1

私はこのクエリを持っています...

select * from selection_value where id = 14702
14702
14704
14724
14710
14738
14717
14719
14719
14738
14722
14721
14724
14725
14706
14730
14708
14731
14715
14708
14749
14752
14754
14755
14757
14795
14753
14760
14761
14759
14762
14763
14785
14764
14765
14785
14766
14768
14796
14771
14772
14774
14776
14764
14780
14781
14767
14784
14785
14786
14788
14789
14790
14791
14785
14772
14792
14796
14785
14797
14798
14799
14800
14802
14778
14803
14758
14765
14762
14781
14785
14786
14808
14793
14805
14807
14808

これが機能しないことがわかったので、これらすべてのIDのデータをこの順序で取得するための最良の方法は何でしょうか。

これは可能ですか?

4

5 に答える 5

4

使用IN

SELECT * FROM selection_value WHERE id IN (14702, 14702, 14704, etc.) ORDER BY id

*編集:*

現在の特定の順序を保持するには、新しいテーブルを作成します。

CREATE TABLE2 (id INT IDENTITY(1,1), id_number int)

このテーブルに、番号を並べ替えるのに必要な順序で追加します。次に、次のクエリのようなものを使用して、特定の順序でIDを抽出できます。

SELECT selection_Value.* FROM selection_value JOIN Table2 ON selection_Value.id = table2.id_number ORDER BY Table2.id
于 2012-11-07T18:55:54.827 に答える
4

ある列で一致する値と別の列での順序を使用して派生テーブルを作成できます。これをテーブルに結合し、順序列で並べ替えます。

  select *
    from (
         select 1 ord, 14702 value union all
         select 2, 14704 union all
         select 3, 14724 union all
         select 4, 14710 union all
         select 5, 14738
         ) x
    join selection_value t on t.id = x.value
order by ord;
于 2012-11-07T18:56:15.247 に答える
2

INカンマ区切りの値を持つ句を使用します。

select * from selection_value where id IN (14702,14703, so on) ORDER BY ID
于 2012-11-07T18:57:32.433 に答える
1

あなたの質問は完全には明確ではありませんが、おそらく:

SELECT * FROM selection_value 
WHERE id IN
      (SELECT id FROM table ORDER BY id ASC)

注文が指摘されたばかりです(クエリは別のテーブルからデータをプルする必要がありますか?):

select * from selection_value where id IN (14702,14702,14704,14724,14710,14738,14717,14719,14719,14738,14722,14721,14724,14725,14706,14730,14708,14731,14715,14708,14749,14752,14754,14755,14757,14795,14753,14760,14761,14759,14762,14763,14785,14764,14765,14785,14766,14768,14796,14771,14772,14774,14776,14764,14780,14781,14767,14784,14785,14786,14788,14789,14790,14791,14785,14772,14792,14796,14785,14797,14798,14799,14800,14802,14778,14803,14758,14765,14762,14781,14785,14786,14808,14793,14805,14807,14808)
于 2012-11-07T18:57:25.427 に答える
-1

質問をメモ帳++に貼り付け、正規表現モードで次の検索と置換を実行します。

  • \ r->''
  • \ n-> \ nunion all \ nselect * from selection_value where id =

出来上がり!

select * from selection_value where id = 14702
union all
select * from selection_value where id =14702
union all
select * from selection_value where id =14704
union all
select * from selection_value where id =14724
union all
select * from selection_value where id =14710
union all
select * from selection_value where id =14738
union all
select * from selection_value where id =14717
union all
select * from selection_value where id =14719
union all
select * from selection_value where id =14719
union all
select * from selection_value where id =14738
union all
select * from selection_value where id =14722
union all
select * from selection_value where id =14721
union all
select * from selection_value where id =14724
union all
select * from selection_value where id =14725
union all
select * from selection_value where id =14706
union all
select * from selection_value where id =14730
union all
select * from selection_value where id =14708
union all
select * from selection_value where id =14731
union all
select * from selection_value where id =14715
union all
select * from selection_value where id =14708
union all
select * from selection_value where id =14749
union all
select * from selection_value where id =14752
union all
select * from selection_value where id =14754
union all
select * from selection_value where id =14755
union all
select * from selection_value where id =14757
union all
select * from selection_value where id =14795
union all
select * from selection_value where id =14753
union all
select * from selection_value where id =14760
union all
select * from selection_value where id =14761
union all
select * from selection_value where id =14759
union all
select * from selection_value where id =14762
union all
select * from selection_value where id =14763
union all
select * from selection_value where id =14785
union all
select * from selection_value where id =14764
union all
select * from selection_value where id =14765
union all
select * from selection_value where id =14785
union all
select * from selection_value where id =14766
union all
select * from selection_value where id =14768
union all
select * from selection_value where id =14796
union all
select * from selection_value where id =14771
union all
select * from selection_value where id =14772
union all
select * from selection_value where id =14774
union all
select * from selection_value where id =14776
union all
select * from selection_value where id =14764
union all
select * from selection_value where id =14780
union all
select * from selection_value where id =14781
union all
select * from selection_value where id =14767
union all
select * from selection_value where id =14784
union all
select * from selection_value where id =14785
union all
select * from selection_value where id =14786
union all
select * from selection_value where id =14788
union all
select * from selection_value where id =14789
union all
select * from selection_value where id =14790
union all
select * from selection_value where id =14791
union all
select * from selection_value where id =14785
union all
select * from selection_value where id =14772
union all
select * from selection_value where id =14792
union all
select * from selection_value where id =14796
union all
select * from selection_value where id =14785
union all
select * from selection_value where id =14797
union all
select * from selection_value where id =14798
union all
select * from selection_value where id =14799
union all
select * from selection_value where id =14800
union all
select * from selection_value where id =14802
union all
select * from selection_value where id =14778
union all
select * from selection_value where id =14803
union all
select * from selection_value where id =14758
union all
select * from selection_value where id =14765
union all
select * from selection_value where id =14762
union all
select * from selection_value where id =14781
union all
select * from selection_value where id =14785
union all
select * from selection_value where id =14786
union all
select * from selection_value where id =14808
union all
select * from selection_value where id =14793
union all
select * from selection_value where id =14805
union all
select * from selection_value where id =14807
union all
select * from selection_value where id =14808
于 2012-11-07T19:21:17.010 に答える