多个升序在MySQL中不起作用 [英] Multiple ascending order is not working in Mysql

查看:104
本文介绍了多个升序在MySQL中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表称为request,有三列称为Id, want, teach.我必须按升序显示wantteach列,并且我不想显示NULL和空白行.

I have one table called as request and there are three columns called as Id, want, teach. I have to display want and teach column in ascending order and I don't want to display NULL and blank rows.

我尝试查询仅want列以升序显示,但teach列未以升序显示.

I tried query only want column is displaying in ascending order but teach column is not displaying in ascending.

  SELECT want, teach FROM request WHERE want IS NOT NULL OR want !='' AND teach IS NOT NULL OR teach !='' GROUP BY want, teach ORDER BY want ASC, teach ASC

如果我写ORDER BY示教ASC,则要ASC,则示教列将以升序显示,而要显示DESC顺序. 您能帮我吗?

If I write ORDER BY teach ASC, want ASC then teach column is displaying in Ascending order and want is showing DESC order. Would you help me in this?

Chech左侧栏是想要的,而右侧栏是教导的.我正在得到这样的输出.左侧列为ASC订单,但右侧为DESC

Chech left side column is want and right side column is teach. I am getting output like this. left side column is ASC order but right side is showing DESC

推荐答案

首先,您需要了解

如果您给第1,第2升序,它将在第1列优先升序,并以此为依托,将第2列升序. 例如

if you give 1st,2nd asc order it will frist asc the 1st column and depend on this it will asc 2nd column. for example

1st  2nd               
1    b
2    d
3    a
2    a
1    a

通过

 1st   2nd 
  1     a
  1     b
  2     a
  2     d
  3     a

因此您需要进行不同的查询

So you need to different query

     SELECT want FROM request WHERE want IS NOT NULL OR want !='' GROUP BY 
 want ORDER BY want ASC

     SELECT teach FROM request WHERE teach IS NOT NULL OR teach !='' GROUP
 BY  teach ORDER BY teach ASC

这篇关于多个升序在MySQL中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆