MySQL:如何在多列上进行ORDER BY?

时间:2016-01-07 12:37:24

标签: mysql sql

我在表格中有以下列

type | date_1 | date_2 | date_3

类型列是

ENUM('1','2','3')

我需要按日期列进行排序,但要在每一行使用基于type列的相应列。

2 个答案:

答案 0 :(得分:2)

You can pass button click id as a parameter in querystring and then access that querystring value from other page. Here is code for your page1: <asp:Button ID="Button1" runat="server" Text="Cycle Test 1" class="studentdetbtn" OnClientClick="return OpenPage(this);" /> <script> function OpenPage(elemt) { var id = $(elemt).attr("id"); window.open('internalmark.aspx?param=' + id , 'Internal Mark'); } </script> Here is code for your page2 i.e "internalmark.aspx": <script> $(document).ready(function () { var qs = getQueryStrings(); var GetButtonId= qs["param"]; alert("here is the button id: "+ GetButtonId) }); function getQueryStrings() { var assoc = {}; var decode = function (s) { return decodeURIComponent(s.replace(/\+/g, " ")); }; var queryString = location.search.substring(1); var keyValues = queryString.split('&'); for (var i in keyValues) { var key = keyValues[i].split('='); if (key.length > 1) { assoc[decode(key[0])] = decode(key[1]); } } return assoc; } </script> 中使用case表达式来获取正确的值:

order by

答案 1 :(得分:1)

尝试类似

的内容
SELECT * 
FROM your_table 
ORDER BY IF(type='1', date_1, IF(type='2', date_2, date_3))