mysql查询问题查询语句按照降序

已知 我有一张 分数表 tab_gameintegral

分数字段为score 但是每个ID 都最少有3个score

我想求出 每个Id的最高分数,并且将整张表的分数 按照降续来排列

7个回答

一个ID对应三个分数,问题是:第一个分数为一类最高,第二个分数为二类分数最低,那你这个ID想让他排哪里?

lliuhongyang
刘弘扬 我只想求出 这个Id 最高的分数. 然后求出整张表分数排序
接近 3 年之前 回复

求出每个ID对应的最高分,并且根据分数倒序排序。这个语句应该能满足你的要求。
select id,max(score) score from tab_gameintegral group by id order by score desc

lliuhongyang
刘弘扬 谢谢大神回答, 语句没毛病 只是刚才采纳点你的时候 点错了
接近 3 年之前 回复

你的意思是按照每个ID按照最高分排序对吧,意思就是一个id中3个score只看最高分的score?

使用UNION 表关联后在排序

排序是根据什么排?每个ID的最高分?

select id,max(score) score from tab_gameintegral group by id order by score desc

order by score desc

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
mysql如何根据字段1与字段2的差值按照降序排序

如:表table,两字段:c1,c2,我想select * from table ,条件是c1与c2的差值按照降序排序,求指点

mysql 查询 求sql语句

1. User表用于记录用户相关信息, Photo表用于记录用户的照片信息, 两个表的定义如下: CREATE TABLE User( --用户信息表 UserId bigint, --用户唯一id Account varchar(30) --用户唯一帐号 ); CREATE TABLE Photo( --照片信息表 PhotoId bigint, --照片唯一id UserId bigint, --照片所属用户id AccessCount int, --访问次数 Size bigint --照片文件实际大小 ) 1) 请给出SQL打印帐号为"dragon"的用户访问次数最多的5张照片的id; 2) 给出SQL打印拥有总的照片文件大小(total_size)最多的前10名用户的id, 并根据total_size降序排列 3) 为优化上面两个查询, 需要在User和Photo表上建立什么样的索引? 2. 数据库中有表User(id, name, age): 表中数据可能会是以下形式: id name age 001 张三 56 002 李四 25 003 王五 56 004 赵六 21 005 钱七 39 006 孙八 56 .............. 由于人员年龄有可能相等, 请写出SQL语句, 用于查询age最大的人员中, id最小的一个记录

如何对查询的结果按照自己的规则排序

Select * from f_account where ACCT_ID in (3,4,2) ORDER BY charindex(','+convert(varchar,ACCT_ID)+',','3,4,2') 这是在网上找的,不知道 是不是写的不对,报错 [Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'varchar,ACCT_ID)+',','3,4,2')' at line 3

MySQL按时间戳排序预先排序的记录

<div class="post-text" itemprop="text"> <p>I'm having a problem with a MySQL query. I've been following: <a href="https://stackoverflow.com/questions/435703/how-to-select-the-most-recent-set-of-dated-records-from-a-mysql-table">How to select the most recent set of dated records from a mysql table</a> and what I'm trying to do is select the most recient record and sort it by the sales_total field. So first I have to sort by max(timestamp) then sort again by sales_total. I've modified the solution offered above as follows:</p> <pre><code>$query = "(SELECT * FROM (SELECT * FROM table_name WHERE year =\'2013\' AND category=\'Network\' ORDER BY timestamp DESC) as t1 GROUP BY name) ORDER BY sales_total DESC"; $result = mysql_query($query) or die("Query failed"); </code></pre> <p>This runs perfectly in PHPMyadmin, however If I try and execute the same query in a PHP script I get a Query Failed error. Anyone know why the above seems to work in PHPMyadmin but not in PHP?</p> <hr> <p>My PHP query is as follows:</p> <pre><code>$query = "(SELECT * FROM (SELECT * FROM table_name WHERE category=\'Network\' ORDER BY timestamp DESC) as t1 GROUP BY name) ORDER BY sales_total DESC"; </code></pre> </div>

MYSQL合并两个表的查询结果并排序

已解决,SQL语句如下: ``` SELECT * FROM ( ( SELECT post.post_id AS id, 'P' AS type, post.title AS title, post_time AS time FROM `ts_weiba_post` AS `post` WHERE `post`.`post_uid` = 41 ) UNION ( SELECT reply.reply_id AS id, 'R' AS type, reply.content AS title, reply.ctime AS time FROM `ts_weiba_reply` AS `reply` WHERE `reply`.`uid` = 41 ) ) AS alldate ORDER BY time DESC ``` --------------------------------------------------------------------------- ts_weiba_post是用户发帖表 ts_weiba_reply是用户评论表 问题: 需要将用户的发帖数据和回复数据合并在一起并依据时间排序。 即从ts_weiba_post中查询post_uid等于41的数据和ts_weiba_reply中uid等于41的数据,并合并查询结果后依据ts_weiba_post的post_time和ts_weiba_reply的ctime排序 ``` /* Navicat MySQL Data Transfer Source Server : 127.0.0.1 Source Server Version : 50547 Source Host : 127.0.0.1:3306 Source Database : xiaotiane Target Server Type : MYSQL Target Server Version : 50547 File Encoding : 65001 Date: 2016-07-02 21:58:15 */ SET FOREIGN_KEY_CHECKS=0; -- ---------------------------- -- Table structure for ts_weiba_post -- ---------------------------- DROP TABLE IF EXISTS `ts_weiba_post`; CREATE TABLE `ts_weiba_post` ( `post_id` int(11) NOT NULL AUTO_INCREMENT COMMENT '帖子ID', `weiba_id` int(11) NOT NULL COMMENT '所属微吧ID', `post_uid` int(11) NOT NULL COMMENT '发表者uid', `title` varchar(255) NOT NULL COMMENT '帖子标题', `content` text NOT NULL COMMENT '帖子内容', `post_time` int(11) NOT NULL COMMENT '发表时间', `reply_count` int(10) DEFAULT '0' COMMENT '回复数', `read_count` int(10) DEFAULT '0' COMMENT '浏览数', `last_reply_uid` int(11) DEFAULT '0' COMMENT '最后回复人', `last_reply_time` int(11) DEFAULT '0' COMMENT '最后回复时间', `digest` tinyint(1) DEFAULT '0' COMMENT '全局精华 0-否 1-是', `top` tinyint(1) DEFAULT '0' COMMENT '置顶帖 0-否 1-吧内 2-全局', `lock` tinyint(1) DEFAULT '0' COMMENT '锁帖(不允许回复)0-否 1-是', `recommend` tinyint(1) DEFAULT '0' COMMENT '是否设为推荐', `recommend_time` int(11) DEFAULT '0' COMMENT '设为推荐的时间', `is_del` tinyint(2) DEFAULT '0' COMMENT '是否已删除 0-否 1-是', `feed_id` int(11) NOT NULL COMMENT '对应的分享ID', `reply_all_count` int(11) NOT NULL DEFAULT '0' COMMENT '全部评论数目', `attach` varchar(255) DEFAULT NULL, `praise` int(11) DEFAULT '0' COMMENT '喜欢', `from` tinyint(2) DEFAULT '0' COMMENT '客户端类型,0:网站;1:手机网页版;2:android;3:iphone', `top_time` int(11) DEFAULT NULL, `is_index` tinyint(2) DEFAULT '0', `index_img` int(11) DEFAULT NULL, `is_index_time` int(11) DEFAULT NULL, PRIMARY KEY (`post_id`), KEY `id_recommend` (`recommend_time`,`weiba_id`,`recommend`) USING BTREE, KEY `post_time` (`post_time`,`weiba_id`) USING BTREE ) ENGINE=MyISAM AUTO_INCREMENT=895 DEFAULT CHARSET=utf8; -- ---------------------------- -- Records of ts_weiba_post -- ---------------------------- INSERT INTO `ts_weiba_post` VALUES ('883', '8', '41', 'title_3', 'content_3', '1467078402', '0', '1', '1', '1467078402', '0', '0', '0', '0', '0', '0', '32', '0', null, '0', '0', null, '0', null, null); INSERT INTO `ts_weiba_post` VALUES ('881', '8', '41', 'title_1', 'content_1', '1467078185', '0', '0', '1', '1467078185', '0', '0', '0', '0', '0', '0', '0', '0', null, '0', '0', null, '0', null, null); INSERT INTO `ts_weiba_post` VALUES ('882', '8', '41', 'title_2', 'content_2', '1467078260', '0', '1', '1', '1467078260', '0', '0', '0', '0', '0', '0', '31', '0', null, '0', '0', null, '0', null, null); INSERT INTO `ts_weiba_post` VALUES ('885', '9', '41', 'title_4', 'content_4', '1467078496', '0', '1', '1', '1467078496', '0', '0', '0', '0', '0', '0', '33', '0', null, '0', '0', null, '0', null, null); INSERT INTO `ts_weiba_post` VALUES ('886', '9', '41', 'title_5', 'content_5', '1467078606', '0', '6', '1', '1467078606', '0', '0', '0', '0', '0', '0', '34', '0', null, '1', '0', null, '0', null, null); INSERT INTO `ts_weiba_post` VALUES ('887', '10', '41', 'title_6', 'content_6', '1467078692', '0', '1', '1', '1467078692', '0', '0', '0', '0', '0', '0', '35', '0', null, '0', '0', null, '0', null, null); INSERT INTO `ts_weiba_post` VALUES ('888', '10', '41', 'title_7', 'content_7', '1467078911', '2', '8', '578', '1467083920', '0', '0', '0', '0', '0', '0', '36', '2', null, '0', '0', null, '0', null, null); INSERT INTO `ts_weiba_post` VALUES ('889', '10', '41', 'title_8', 'content_8', '1467078989', '0', '6', '1', '1467078989', '0', '0', '0', '0', '0', '0', '37', '0', null, '0', '0', null, '0', null, null); INSERT INTO `ts_weiba_post` VALUES ('890', '5', '232', 'title_9', 'content_9', '1467084362', '0', '4', '232', '1467084362', '0', '0', '0', '0', '0', '0', '38', '0', null, '0', '0', null, '0', null, null); INSERT INTO `ts_weiba_post` VALUES ('891', '3', '579', 'title_10', 'content_10', '1467084380', '0', '5', '579', '1467084380', '0', '0', '0', '0', '0', '0', '39', '0', null, '0', '0', null, '0', null, null); INSERT INTO `ts_weiba_post` VALUES ('892', '6', '232', 'title_11', 'content_11', '1467084538', '0', '8', '232', '1467084538', '0', '0', '0', '0', '0', '0', '40', '0', null, '0', '0', null, '0', null, null); INSERT INTO `ts_weiba_post` VALUES ('893', '3', '536', 'title_12', 'content_12', '1467090574', '3', '18', '579', '1467091548', '0', '0', '0', '0', '0', '0', '41', '3', null, '1', '0', null, '0', null, null); INSERT INTO `ts_weiba_post` VALUES ('894', '3', '41', 'title_13', 'content_13', '1467464403', '0', '1', '41', '1467464403', '0', '0', '0', '0', '0', '0', '42', '0', null, '0', '0', null, '0', null, null); -- ---------------------------- -- Table structure for ts_weiba_reply -- ---------------------------- DROP TABLE IF EXISTS `ts_weiba_reply`; CREATE TABLE `ts_weiba_reply` ( `reply_id` int(11) NOT NULL AUTO_INCREMENT COMMENT '回复ID', `weiba_id` int(11) NOT NULL COMMENT '所属微吧', `post_id` int(11) NOT NULL COMMENT '所属帖子ID', `post_uid` int(11) NOT NULL COMMENT '帖子作者UID', `uid` int(11) NOT NULL COMMENT '回复者ID', `to_reply_id` int(11) NOT NULL DEFAULT '0' COMMENT '回复的评论id', `to_uid` int(11) NOT NULL DEFAULT '0' COMMENT '被回复的评论的作者的uid', `ctime` int(11) NOT NULL COMMENT '回复时间', `content` text NOT NULL COMMENT '回复内容', `is_del` tinyint(2) DEFAULT '0' COMMENT '是否已删除 0-否 1-是', `comment_id` int(11) NOT NULL COMMENT '对应的分享评论ID', `storey` int(11) NOT NULL DEFAULT '0' COMMENT '绝对楼层', `attach_id` int(11) NOT NULL, `digg_count` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`reply_id`) ) ENGINE=MyISAM AUTO_INCREMENT=2333 DEFAULT CHARSET=utf8; -- ---------------------------- -- Records of ts_weiba_reply -- ---------------------------- INSERT INTO `ts_weiba_reply` VALUES ('1', '1', '1', '1', '1', '0', '0', '1464331112', '123123123', '0', '1', '0', '0', '1'); INSERT INTO `ts_weiba_reply` VALUES ('5', '1', '25', '14', '1', '0', '0', '1464630201', 'lalala[bizui]', '0', '5', '0', '0', '0'); INSERT INTO `ts_weiba_reply` VALUES ('6', '1', '25', '14', '1', '0', '0', '1464630224', '111', '0', '6', '0', '0', '0'); INSERT INTO `ts_weiba_reply` VALUES ('12', '6', '702', '1', '579', '0', '0', '1464774363', '?', '0', '12', '0', '0', '0'); INSERT INTO `ts_weiba_reply` VALUES ('11', '6', '705', '1', '578', '0', '0', '1464766121', '[ciya]', '0', '11', '0', '0', '0'); INSERT INTO `ts_weiba_reply` VALUES ('13', '2', '718', '579', '1', '0', '0', '1464859276', '121212', '0', '13', '0', '0', '0'); INSERT INTO `ts_weiba_reply` VALUES ('14', '5', '747', '12', '12', '0', '0', '1467082511', '发布会已经成功举办', '0', '14', '0', '0', '0'); INSERT INTO `ts_weiba_reply` VALUES ('15', '2', '58', '30', '14', '0', '0', '1467082621', '[ciya]', '0', '15', '0', '0', '0'); INSERT INTO `ts_weiba_reply` VALUES ('16', '2', '58', '30', '232', '0', '0', '1467083224', '[guzhang]', '0', '16', '0', '0', '0'); INSERT INTO `ts_weiba_reply` VALUES ('17', '5', '749', '12', '578', '0', '0', '1467083594', '[qiang]', '0', '17', '0', '0', '0'); INSERT INTO `ts_weiba_reply` VALUES ('18', '10', '888', '1', '578', '0', '0', '1467083701', '[ciya]', '0', '18', '0', '0', '0'); INSERT INTO `ts_weiba_reply` VALUES ('22', '2', '58', '30', '578', '0', '0', '1467083878', '[liuhan][liuhan]', '0', '22', '0', '0', '0'); INSERT INTO `ts_weiba_reply` VALUES ('21', '2', '58', '30', '578', '0', '0', '1467083854', '[huaixiao]', '0', '21', '0', '0', '0'); INSERT INTO `ts_weiba_reply` VALUES ('23', '10', '888', '1', '578', '0', '0', '1467083920', '[ku][ku]', '0', '23', '0', '0', '0'); INSERT INTO `ts_weiba_reply` VALUES ('24', '3', '893', '536', '536', '0', '0', '1467091173', '有人在吗', '0', '24', '0', '0', '0'); INSERT INTO `ts_weiba_reply` VALUES ('25', '3', '893', '536', '536', '0', '0', '1467091306', '有人在吗?', '0', '25', '0', '0', '0'); INSERT INTO `ts_weiba_reply` VALUES ('26', '3', '893', '536', '579', '0', '0', '1467091548', '[aoman][baiyan]', '0', '26', '0', '0', '0'); INSERT INTO `ts_weiba_reply` VALUES ('27', '2', '58', '30', '536', '0', '0', '1467092560', '[ciya][ciya][ciya][ciya][ciya]', '0', '27', '0', '0', '0'); INSERT INTO `ts_weiba_reply` VALUES ('28', '2', '58', '30', '41', '0', '0', '1467265038', '11111111111', '0', '28', '0', '0', '0'); INSERT INTO `ts_weiba_reply` VALUES ('29', '2', '58', '30', '41', '0', '0', '1467464445', '发布了一条回复1', '0', '29', '0', '0', '0'); INSERT INTO `ts_weiba_reply` VALUES ('30', '2', '58', '30', '41', '0', '0', '1467464445', '发布了一条回复2', '0', '29', '0', '0', '0'); INSERT INTO `ts_weiba_reply` VALUES ('31', '2', '58', '30', '41', '0', '0', '1467464445', '发布了一条回复3', '0', '29', '0', '0', '0'); INSERT INTO `ts_weiba_reply` VALUES ('32', '2', '58', '30', '41', '0', '0', '1467464445', '发布了一条回复4', '0', '29', '0', '0', '0'); ```

sql查询问题 子查询。。。

![图片说明](https://img-ask.csdn.net/upload/201612/10/1481355231_241593.png) 我要查询每个部门工资前3名的

mysql多条件排序查询。。。。

表里有两个时间一个标识符,想实现: 1、先按时间1降序排序(条件:标识符=1) 2、再按时间2升序排序。

查询19年所有客户的订单总金额,并按总金额从大到小排序

用SQL语句,查询2019年所有客户的订单总金额,并按总金额从大到小排序。(客户表customer, 订单表orders, 订单明细表orderitem) ?

mysql插入数据,怎么根据时间字段自动排序

我要写个php代码,在插入数据的时候获取当前时间,并且插入到数据库对应的字段里面,然后整个表根据时间的先后,改变原来的ID值,让最新的数据始终保持ID值为1。 能行么

SQL累加问题,根据日期降序累加

create table User_Salary (UserName nvarchar(200), Month nvarchar(20), Salary int) go insert into User_Salary (UserName,Month,Salary ) values('AAA','2010/12',1000) insert into User_Salary (UserName,Month,Salary ) values('AAA','2011/01',2000) insert into User_Salary (UserName,Month,Salary ) values('AAA','2011/02',3000) insert into User_Salary (UserName,Month,Salary ) values('BBB','2010/12',2000) insert into User_Salary (UserName,Month,Salary ) values('BBB','2011/01',2500) insert into User_Salary (UserName,Month,Salary ) values('BBB','2011/02',2500) ![图片说明](https://img-ask.csdn.net/upload/201507/18/1437184730_27377.png) 上面是原表格,想实现成(UserName相同,根据日期降序进行汇总,即汇总日期小于此行日期且UserName相同所有数据),如下图 ![图片说明](https://img-ask.csdn.net/upload/201507/18/1437184674_617914.png) 该如何写SQL语句

下拉菜单搜索过滤器排序两个与升序/降序SQL语句冲突的变量

<div class="post-text" itemprop="text"> <p>I am trying to build a dropdown filter search for a database and it seems to be that it is conflicting with the logic statements for ascending/descending order I have in place. </p> <p>When I tried to move the if-statements of the dropdown menu filter above the ascending/descending ordering statements, the filter does not work properly, i.e. when I try to filter for 'Analyzed' it gives me another statuses too. </p> <p>On the other hand, when i tried to move the if-statements of the dropdown filter below the ordering statements, the filter search works fine but when trying to order the table I get a $sql undefined error.</p> <pre><code> print("&lt;form action='patients.php' method='get'&gt;"); // cs = case status print("&lt;select name='cs'&gt; &lt;option selected='selected' value=''&gt;--Select Case Status--&lt;/option&gt; &lt;option value='1'&gt;Pass&lt;/option&gt; &lt;option value='2'&gt;Failed&lt;/option&gt; &lt;option value='3'&gt;Pass With Error&lt;/option&gt; &lt;option value='4'&gt;Indeterminate&lt;/option&gt; &lt;/select&gt;"); // sf = status flagged print("&lt;select name='sf'&gt; &lt;option selected='selected' value=''&gt;--Select Flagged Status--&lt;/option&gt; &lt;option value='Analyzed'&gt;Analyzed Case&lt;/option&gt; &lt;option value='New Case'&gt;New Case&lt;/option&gt; &lt;option value='Updated Case'&gt;Updated Case (New Images)&lt;/option&gt; &lt;option value='None'&gt;No Status Flag&lt;/option&gt; &lt;/select&gt;"); print("&lt;input type='submit' name='search' value='Search'&gt;&lt;/form&gt;"); //print("&lt;a href = 'patients.php?case=failed'&gt;View Failed Cases&lt;/a&gt;&lt;br&gt;&lt;br&gt;"); } printf('&lt;table border=1&gt;&lt;tr&gt;&lt;th&gt;&lt;a href ="patients.php?pID=%s"&gt;Patient ID&lt;/a&gt;',empty($_GET['pID']) || $_GET['pID'] == 'asc' ? 'desc' : 'asc'); printf('&lt;/th&gt;&lt;th&gt;&lt;a href ="patients.php?caseStatus=%s"&gt;Case Status&lt;/a&gt;', empty($_GET['caseStatus']) || $_GET['caseStatus'] == 'asc' ? 'desc' : 'asc'); printf('&lt;/th&gt;&lt;th&gt;Sub Status&lt;/th&gt;&lt;th&gt;Number of Cases&lt;/th&gt;&lt;th&gt;Status Reason&lt;/th&gt;&lt;th&gt;&lt;a href ="patients.php?dateReviewed=%s"&gt;Date Reviewed&lt;/a&gt;', empty($_GET['dateReviewed']) || $_GET['dateReviewed'] == 'asc' ? 'desc' : 'asc'); printf('&lt;/th&gt;&lt;th&gt;&lt;a href ="patients.php?statusFlag=%s"&gt;Status Flag&lt;/a&gt;', empty($_GET['statusFlag']) || $_GET['statusFlag'] == 'asc' ? 'desc' : 'asc'); printf('&lt;/th&gt;&lt;/tr&gt;'); // search filter, takes the case status (cs) and status flag (sf) and filter according to selection if (isset($_GET['cs']) &amp;&amp; isset($_GET['sf']) ) { $cs= $_GET['cs']; $sf= $_GET['sf']; if (($sf==NULL) &amp;&amp; ($cs!==NULL)) { $sql = "SELECT patientid, sub_status_lookup.CASE_STATUS, sub_status_lookup.SUB_STATUS, count(caseid) as cases_count, cases.comments, date_mod, caseid, user_mod, status_flag FROM cases, sub_status_lookup Where cases.status = '".$cs."' Group By patientid, cases.status"; } else if (($sf!==NULL) &amp;&amp; ($cs==NULL)) { $sql = "SELECT patientid, sub_status_lookup.CASE_STATUS, sub_status_lookup.SUB_STATUS, count(caseid) as cases_count, cases.comments, date_mod, caseid, user_mod, status_flag FROM cases, sub_status_lookup Where cases.status_flag = '".$sf."' Group By patientid, cases.status"; } else if (($cs==NULL)&amp;&amp;($sf==NULL)){ $sql = "SELECT patientid, sub_status_lookup.CASE_STATUS, sub_status_lookup.SUB_STATUS, count(caseid) as cases_count, cases.comments, date_mod, caseid, user_mod, status_flag FROM cases, sub_status_lookup Where cases.status = sub_status_lookup.SUB_ID Group By patientid, cases.status"; } else { $sql = "SELECT patientid, sub_status_lookup.CASE_STATUS, sub_status_lookup.SUB_STATUS, count(caseid) as cases_count, cases.comments, date_mod, caseid, user_mod, status_flag FROM cases, sub_status_lookup Where cases.status = '".$cs."' and cases.status_flag = '".$sf."' Group By patientid, cases.status"; } $orderBy ="Order By patientid"; } else { $orderBy = "Order By patientid"; $sql = "SELECT patientid, sub_status_lookup.CASE_STATUS, sub_status_lookup.SUB_STATUS, count(caseid) as cases_count, cases.comments, date_mod, caseid, user_mod, status_flag FROM cases, sub_status_lookup Where cases.status = sub_status_lookup.SUB_ID Group By patientid, cases.status ".$orderBy; } //takes the patient id, status description, count of cases then groups them by patient id ordering them by their status if (isset($_GET['pID'])){ switch($_GET['pID']){ case "asc": $orderBy = " ORDER BY patientid ASC"; break; case "desc": $orderBy = " ORDER BY patientid DESC"; break; default: $orderBy = " ORDER BY patientid ASC"; break; $sql = "SELECT patientid, sub_status_lookup.CASE_STATUS, sub_status_lookup.SUB_STATUS, count(caseid) as cases_count, cases.comments, date_mod, caseid, user_mod, status_flag FROM cases, sub_status_lookup Where cases.status = sub_status_lookup.SUB_ID Group By patientid, cases.status ".$orderBy; } } else if (isset($_GET['caseStatus'])){ switch($_GET['caseStatus']){ case "asc": $orderBy = " ORDER BY sub_status_lookup.CASE_STATUS ASC"; break; case "desc": $orderBy = " ORDER BY sub_status_lookup.CASE_STATUS DESC"; break; default: $orderBy = " ORDER BY sub_status_lookup.CASE_STATUS ASC"; break; $sql = "SELECT patientid, sub_status_lookup.CASE_STATUS, sub_status_lookup.SUB_STATUS, count(caseid) as cases_count, cases.comments, date_mod, caseid, user_mod, status_flag FROM cases, sub_status_lookup Where cases.status = sub_status_lookup.SUB_ID Group By patientid, cases.status ".$orderBy; } } else if (isset($_GET['dateReviewed'])){ switch($_GET['dateReviewed']){ case "asc": $orderBy = " ORDER BY date_mod ASC"; break; case "desc": $orderBy = " ORDER BY date_mod DESC"; break; default: $orderBy = " ORDER BY date_mod ASC"; break; $sql = "SELECT patientid, sub_status_lookup.CASE_STATUS, sub_status_lookup.SUB_STATUS, count(caseid) as cases_count, cases.comments, date_mod, caseid, user_mod, status_flag FROM cases, sub_status_lookup Where cases.status = sub_status_lookup.SUB_ID Group By patientid, cases.status ".$orderBy; } // Updated to work, statusFlag now stored in DB as status_flag 6/4/2013 - Allen } else if (isset($_GET['statusFlag'])){ switch($_GET['statusFlag']){ case "asc": $orderBy = " ORDER BY status_flag ASC"; break; case "desc": $orderBy = " ORDER BY status_flag DESC"; break; default: $orderBy = " ORDER BY status_flag ASC"; break; $sql = "SELECT patientid, sub_status_lookup.CASE_STATUS, sub_status_lookup.SUB_STATUS, count(caseid) as cases_count, cases.comments, date_mod, caseid, user_mod, status_flag FROM cases, sub_status_lookup Where cases.status = sub_status_lookup.SUB_ID Group By patientid, cases.status ".$orderBy; } } else if (isset($_GET['lastUser'])){ switch($_GET['lastUser']){ case "asc": $orderBy = " ORDER BY user_mod ASC"; break; case "desc": $orderBy = " ORDER BY user_mod DESC"; break; default: $orderBy = " ORDER BY user_mod ASC"; break; $sql = "SELECT patientid, sub_status_lookup.CASE_STATUS, sub_status_lookup.SUB_STATUS, count(caseid) as cases_count, cases.comments, date_mod, caseid, user_mod, status_flag FROM cases, sub_status_lookup Where cases.status = sub_status_lookup.SUB_ID Group By patientid, cases.status ".$orderBy; } } else { $orderBy = "Order By patientid"; $sql = "SELECT patientid, sub_status_lookup.CASE_STATUS, sub_status_lookup.SUB_STATUS, count(caseid) as cases_count, cases.comments, date_mod, caseid, user_mod, status_flag FROM cases, sub_status_lookup Where cases.status = sub_status_lookup.SUB_ID Group By patientid, cases.status ".$orderBy; } //commented 5.10.2013 - allen /*while (isset($_GET['sort'])) { $sortOrder = ASC; if ($_GET['sort'] == 'patientID') { $sql .= "Order by patientid ".$sortOrder;} else if ($_GET['sort'] == 'caseStatus') { $sql .= "Order By sub_status_lookup.CASE_STATUS ".$sortOrder;} else if ($_GET['sort'] == 'dateReviewed') { $sql .= "Order by date_mod ".$sortOrder; } else if ($_GET['sort'] == 'statusFlag') { $sql .= "Order by date_mod ".$sortOrder; } } if (!isset($_GET['sort'])) { $sql .= "Order By patientid"; }*/ $result = mysql_query($sql, $connection); $count = 1; $prvPatId = ""; if($result !== FALSE) { while ($record = mysql_fetch_row($result)) { $patient = $record[0]; $statusD = $record[1]; $substatusD = $record[2]; $caseCount = $record[3]; $statusReason = $record[4]; $dateReviewed = $record[5]; $caseID = $record[6]; $lastUser =$record[7]; statusFlagged($patient,$caseID,$dateReviewed); $statusFlagged = $record[8]; //StatusFlag should be working as of 5/30/2013. Please double check $patLink = "&lt;a href='case.php?dirName=".$rootDirectory.$patient."&amp;patient=".$patient."' &gt;".$patient."&lt;/a&gt;"; if($prvPatId == $patient) { $patLink = "&amp;nbsp;"; } else { $count ++; $prvPatId = $patient; } print("&lt;tr&gt;&lt;td&gt;".$patLink."&lt;/td&gt;&lt;td&gt;".$statusD."&lt;/td&gt;&lt;td&gt;".$substatusD."&lt;/td&gt;&lt;td&gt;".$caseCount."&lt;/td&gt;&lt;td&gt;".$statusReason."&lt;/td&gt;&lt;td&gt;".$dateReviewed."&lt;/td&gt;&lt;td&gt;".$statusFlagged."&lt;/td&gt;&lt;/tr&gt;"); } } mysql_free_result($result); //at the end prints the total number of patients (patient ids- unique) print("&lt;tr&gt;&lt;th colspan=3&gt;Total Patients: ".$count."&lt;/th&gt;&lt;/tr&gt;"); print("&lt;/table&gt;" </code></pre> </div>

请教SQL查询语句,如何实现置顶功能,并将置顶和未置顶的数据按某一顺序排序

如题,求助!如何实现置顶功能,并将置顶和未置顶的数据按某一顺序排序 select * from **** order by top,time 这样不行

在网上书店数据库中进行简单查询

![图片说明](https://img-ask.csdn.net/upload/202006/02/1591081223_377702.jpg)![图片说明](https://img-ask.csdn.net/upload/202006/02/1591081238_299188.jpg)![图片说明](https://img-ask.csdn.net/upload/202006/02/1591081252_971451.jpg)![图片说明](https://img-ask.csdn.net/upload/202006/02/1591081265_751940.jpg)![图片说明](https://img-ask.csdn.net/upload/202006/02/1591081275_66619.jpg) 项目1:在网上书店数据库中进行简单查询 (1)查询会员表,输出积分高于500的会员昵称和联系电话 (2)查询会员表,输出积分低于200的会员的昵称和联系电话,并且分别用英文username、telephone指定别名 (3)查询会员表,输出e-mail是QQ邮箱的会员的昵称和e-mail (4)查询订购表,输出订购日期是2016年10月的订单的详细信息 (5)查询订购表,输出订货的会员的编号,要求删除重复行 (6)查询图书表,输出图书的名称和价格,并把查询结果按价格降序排列 (7)查询图书表,输出价格最高的三种图书的名称和价格 项目2:在网上书店数据库查询中使用集合函数 (1)查询图书表,输出所有图书的最高价格,最低价格,平均价格 (2)查询图书表,输出每一类图书的数量 (3)查询图书表,输出每一类图书的打折价格中,最高价格,最低价格,平均价格 (4)查询订购表,输出订购超过3本的会员的编号和订购数量 项目3:在网上书店数据库查询中使用连接查询和子查询 (1)输出所有图书的图书名称、价格以及所属类别名称 (2)输出订购了“平凡的世界”的会员昵称、联系电话、订购数量 (3)输出订购了图书的会员的昵称和联系电话 (4)输出没人订购的图书的名称和价格 (5)输出详细订购信息,包括订购图书的会员呢称,联系电话,所订图书名称,数量,价格,折扣价

在servlet写sql语句好还是在Dao层的实现类写sql语句好

在servlet写sql语句好还是在Dao层的实现类写sql语句好?我同学说在servlet写sql语句比较灵活,比较好,各位大神怎么看?

mybatis多表连接查询,多字段排序,排序字段在主表,也在另一张表

![](https://img-ask.csdn.net/upload/201904/18/1555555864_832409.png) 图一是关联了本表的字段(按照apart_id排序),不懂另一张表的字段如何关联 ![图片说明](https://img-ask.csdn.net/upload/201904/18/1555556119_858775.png) 图二本表的数据库表 ![图片说明](https://img-ask.csdn.net/upload/201904/18/1555556165_655130.png) 图三是关联的另一张数据库表![图片说明](https://img-ask.csdn.net/upload/201904/18/1555556251_525727.png) 图四是主表的查询mapper文件语句 我想先按照apart_id排序,再按照apartroom_abc排序,再按照apartroom_dorm 排序,不懂怎么弄了

查询每个学生需要补考(小于60分)的课程的平均分,并以平均分排序

![图片](https://img-ask.csdn.net/upload/201612/18/1482044288_370952.jpg)

Java数据库order by ? limit ?,?(排序带分页)问题

如题,关于第一个排序不起作用(一直是默认排序)。不知道大家在开发中有没有遇见这个问题。但是在mysql命令行可以使用。如何解决?急着用!在线等

如何按SQL时间日期/ unix时间戳聚合/分组php数组?

<div class="post-text" itemprop="text"> <p>How to count/group data from array into hours from MySQL timedate format or unix timestamp?</p> <p>My array:</p> <pre><code>Array ( [0] =&gt; Array ( [0] =&gt; id [1] =&gt; name [2] =&gt; 2013-01-10 00:36:00 ) [1] =&gt; Array ( [0] =&gt; id [1] =&gt; name [2] =&gt; 2013-01-10 00:36:00 ) ) </code></pre> <p>How to shrink thousands of items like this and agregate them somehow to hours or even days? I just need rough number of rows with given hour in specyfic day.</p> </div>

where后怎么加case when 判断?

SELECT 类型,异动日期,操作时间,签约单位,所属公司,编号,姓名,一级部门,二级部门,三级部门,职位,入职日期,转正日期,离职日期,异动后一级部门,异动后二级部门,异动后三级部门,异动后职位 FROM HM_RYTRANS_BB WHERE 异动日期>='2017-01-01' AND 异动日期<='2017-04-01' OR 操作时间>='2017-01-01' AND 操作时间<='2017-04-01' and b01_dept_code like '101%' ORDER BY 类型,所属公司,A0190 这个可以用WHEN去判断吗? 怎么写呢? --- 需求 ---1、异动日期不为空、操作时间为空 那么就按照异动日期筛选数据 ---2、当操作日期不为空、异动时间为空 那么就按照操作时间筛选数据 ---3、当异动日期和操作时间均不为空, 那么按照异动日期和操作时间筛选

YOLOv3目标检测实战:训练自己的数据集

YOLOv3目标检测实战:训练自己的数据集

150讲轻松搞定Python网络爬虫

150讲轻松搞定Python网络爬虫

实用主义学Python(小白也容易上手的Python实用案例)

实用主义学Python(小白也容易上手的Python实用案例)

我说我不会算法,阿里把我挂了。

不说了,字节跳动也反手把我挂了。

立方体线框模型透视投影 (计算机图形学实验)

计算机图形学实验 立方体线框模型透视投影 的可执行文件,亲测可运行,若需报告可以联系我,期待和各位交流

2019 AI开发者大会

2019 AI开发者大会

组成原理课程设计(实现机器数的真值还原等功能)

实现机器数的真值还原(定点小数)、定点小数的单符号位补码加减运算、定点小数的补码乘法运算和浮点数的加减运算。

C/C++跨平台研发从基础到高阶实战系列套餐

一 专题从基础的C语言核心到c++ 和stl完成基础强化; 二 再到数据结构,设计模式完成专业计算机技能强化; 三 通过跨平台网络编程,linux编程,qt界面编程,mfc编程,windows编程,c++与lua联合编程来完成应用强化 四 最后通过基于ffmpeg的音视频播放器,直播推流,屏幕录像,

MFC一站式终极全套课程包

该套餐共包含从C小白到C++到MFC的全部课程,整套学下来绝对成为一名C++大牛!!!

软件测试2小时入门

软件测试2小时入门

三个项目玩转深度学习(附1G源码)

三个项目玩转深度学习(附1G源码)

计算机图形学-球的光照模型课程设计

计算机图形学-球的光照模型,有代码完美运行,有课程设计书

Linux常用命令大全(非常全!!!)

Linux常用命令大全(非常全!!!) 最近都在和Linux打交道,感觉还不错。我觉得Linux相比windows比较麻烦的就是很多东西都要用命令来控制,当然,这也是很多人喜欢linux的原因,比较短小但却功能强大。我将我了解到的命令列举一下,仅供大家参考: 系统信息 arch 显示机器的处理器架构 uname -m 显示机器的处理器架构 uname -r 显示正在使用的内核版本 d...

因为看了这些书,我大二就拿了华为Offer

四年了,四年,你知道大学这四年我怎么过的么?

深度学习原理+项目实战+算法详解+主流框架(套餐)

深度学习系列课程从深度学习基础知识点开始讲解一步步进入神经网络的世界再到卷积和递归神经网络,详解各大经典网络架构。实战部分选择当下最火爆深度学习框架PyTorch与Tensorflow/Keras,全程实战演示框架核心使用与建模方法。项目实战部分选择计算机视觉与自然语言处理领域经典项目,从零开始详解算法原理,debug模式逐行代码解读。适合准备就业和转行的同学们加入学习! 建议按照下列课程顺序来进行学习 (1)掌握深度学习必备经典网络架构 (2)深度框架实战方法 (3)计算机视觉与自然语言处理项目实战。(按照课程排列顺序即可)

fakeLocation13.5.1.zip

fakeLocation13.5.1 虚拟定位 ios13.5.1的最新驱动下载,iPhone/iPad免越狱虚拟定位工具Location-cleaned驱动已更新

UnityLicence

UnityLicence

Python可以这样学(第一季:Python内功修炼)

Python可以这样学(第一季:Python内功修炼)

Python+OpenCV计算机视觉

Python+OpenCV计算机视觉

土豆浏览器

土豆浏览器可以用来看各种搞笑、电影、电视剧视频

【数据结构与算法综合实验】欢乐连连看(C++ & MFC)案例

这是武汉理工大学计算机学院数据结构与算法综合实验课程的第三次项目:欢乐连连看(C++ & MFC)迭代开发代码。运行环境:VS2017。已经实现功能:开始游戏、消子、判断胜负、提示、重排、计时、帮助。

php+mysql学生成绩管理系统

学生成绩管理系统,分三个模块:学生,教师和管理员。 管理员模块:负责学生、老师信息的增删改;发布课程信息的增删改,以便让学生选课;审核老师提交的学生成绩并且打印成绩存档;按照课号查询每个课号的学生成绩

多功能数字钟.zip

利用数字电子计数知识设计并制作的数字电子钟(含multisim仿真),该数字钟具有显示星期、24小时制时间、闹铃、整点报时、时间校准功能

推荐24个国外黄色网站欣赏

在中国清朝,明黄色的衣服只有皇子才有资格穿,慢慢的黄色在中国就成了高贵的颜色。在人们的色彩印象中,黄色也表现为暂停。所以当你的网页设计采用黄色的时候,会让人们在你的网页前停留。 黄色,就像橙色和红色,黄色也是一个暖色。它有大自然、阳光、春天的涵义,而且通常被认为是一个快乐和有希望的色彩。黄色是所有色相中最能发光的颜色,给人轻快,透明,辉煌,充满希望的色彩印象。 黄色是一个高可见的色...

u-boot-2015.07.tar.bz2

uboot-2015-07最新代码,喜欢的朋友请拿去

一学即懂的计算机视觉(第一季)

一学即懂的计算机视觉(第一季)

学生成绩管理系统(PHP + MYSQL)

做的是数据库课程设计,使用的php + MySQL,本来是黄金搭配也就没啥说的,推荐使用wamp服务器,里面有详细的使用说明,带有界面的啊!呵呵 不行的话,可以给我留言!

Windows版YOLOv4目标检测实战:训练自己的数据集

Windows版YOLOv4目标检测实战:训练自己的数据集

C++语言基础视频教程

C++语言基础视频教程

玩转Python-Python3基础入门

玩转Python-Python3基础入门

相关热词 c# 按行txt c#怎么扫条形码 c#打包html c# 实现刷新数据 c# 两个自定义控件重叠 c#浮点类型计算 c#.net 中文乱码 c# 时间排序 c# 必备书籍 c#异步网络通信
立即提问