Is this my understanding of the order by of the sql statement correct?? Rookie Question .

Updated on technology 2024-02-09
15 answers
  1. Anonymous users2024-02-05

    1.It's interesting to understand, but the reality should be: if there are more than two fields after order by, then all the records in the result set are sorted by the previous field, and the same part of the previous field is sorted by the next field. For example:

    order by Gender Age Name.

    The sort result is.

    Male 20 Anyi.

    Male 20 Zhang San.

    Male 30 An Xiaoyi.

    Female 18 Lin Wen.

    Female 18 Wei Feng.

    2.That's right. 3.The result you said is correct, but it's not that "there will always be a default order by id asc", it's that if you don't write order by, the result set will be output in the order in which the data records were physically written.

    4.You can achieve the effect you want.

  2. Anonymous users2024-02-04

    It doesn't have to be that complicated, just remember one thing :

    order by a,b

    Sort by a first, then by b if the order of a is the same.

    As for whether it is in ascending order or descending order, (asc and desc are not written by default, asc), writing desc is descending.

    It's as simple as that, and if you think about it too much, it's troublesome.

    Above, I hope it will help you.

  3. Anonymous users2024-02-03

    The understanding is correct, but the formulation is somewhat cumbersome.

    Order by is parsed in left-to-right order, and the default is ASC (non-descending).

    from,where parses from right to left, so the fewer table records on the far right, the better, and the more accurate the conditions on the right, the better.

    For example: select .from tb1,tb2 where f1>1000 and f2='samsung'

    tb1 has 10000 records, tb2 has 100 records, f2='samsung'More accurate than f1>1000.

  4. Anonymous users2024-02-02

    Order pretty much does what it means.

    The top field should be a bit: default 0, top 1, not top 0

    select ..from ..order by top desc, last modified desc

    If you sort by ID, then the replies are useless.

  5. Anonymous users2024-02-01

    The landlord has quick thinking and clear thinking, and he has written an encyclopedia for order by use, which is very correct.

  6. Anonymous users2024-01-31

    Pretty much correct.

    However, the top part should be set to the top field as bit.

    Then order by top

  7. Anonymous users2024-01-30

    Why doubt yourself? Your understanding is absolutely correct!

  8. Anonymous users2024-01-29

    Order by id desc does not write desc, which means ascasc is the default sort.

    If you use the Zhenxu Jingde statement to query in sqlsever, change the equal sign after where to zhi to *=i.e., left join).

    One of the more confusing points is that count() is used to count the number of tuples, order by is followed by count() to count the numerical value, and order by is used to sort the query results in ascending order (asc) or descending order (desc) of one or more attribute columns. Note that the attribute column is sorted, not a specific value of caution.

  9. Anonymous users2024-01-28

    Order by id desc does not write desc, which means ascasc is the default sort.

    If you use that statement in sqlsever, change the equal sign after where to *= (i.e., left join).

    One of the more confusing points is that count() is used to count the number of tuples, order by is followed by count(), and order by is used to sort the query results in ascending order (asc) or descending order (desc) of one or more attribute columns. Note that the attribute column is sorted, not a specific numeric value.

  10. Anonymous users2024-01-27

    order by @id should not be wrong, the default is in ascending order, unless you have a problem with your @id variable and want to have multiple order by, order by @id , order by @name desc

  11. Anonymous users2024-01-26

    I'm not going to say anything, just give you an example, no matter how much I say, there are no examples that are useful.

    select name,count(*)numberfrom users

    group by name

    order by 2 desc

    Query the number of people with the same name in the users table, and sort them according to the number of names with the most duplicate names.

  12. Anonymous users2024-01-25

    Group by first

    Then order by

    Order by should always be executed last.

  13. Anonymous users2024-01-24

    group by is grouping, order by is sorting, first group by and then order by

  14. Anonymous users2024-01-23

    Use group by first, then order by, and order by is always last.

  15. Anonymous users2024-01-22

    The order by statement is used forAccording to the specified columnsRightResult setConductedSorting

    order by statementDefaultIn accordance withAscendingSort the records.

    If you wish to follow theDescendingYou can use it to sort recordsdescKeywords.

    Note: When sorting strings, pressThe first characterofASCII valuearrangement, if the first character is the same, look backward one bit.

    The original table (used in the example):

    orders table:

    Example 1 displays the company name in alphabetical order:

    select company, ordernumber from orders order by company

    Example 2 displays the company name in alphabetical order and the ordernumber in numerical order

    select company, ordernumber from orders order by company, ordernumber

    Example 3 displays the company name in reverse alphabetical order:

    select company, ordernumber from orders order by company desc

    Result: Instance 4

    The company name is displayed in reverse alphabetical order and the sequence number is displayed in numerical order:

    select company, ordernumber from orders order by company desc, ordernumber asc

    Results: Note: There are two equal company names (w3school) in the results above.

    Only this time, when there is the same value in the first column, the second column is in ascending order. This is also the case if some of the values in the first column are nulls.

    Problem description

    If the field used in mysql sorting is character, it will be sorted out like this:

    This sort is compared by character starting with the first character, but not what we want, what we want is:

    Solution

    When sorting, convert the corresponding fields to integers and use the cast function, as follows:

    cast(seat_row as unsigned)

    Convert the seat row column to an unsigned numeric type.

Related questions
11 answers2024-02-09

Press CTRL+M in SQL Server, then execute a SQL statement that you need to analyze, and there will be an Execultion Plan next to the result box, just look at it.

13 answers2024-02-09

Another way to look: select ,select zy ,sum(zy as yjjefrom zy tbkk,zy brry >>>More

16 answers2024-02-09

It can be seen that you really like her, since your relationship is very good now, although he rejected you, it doesn't mean that he really doesn't have you in his heart, maybe she is now confused and confused, and has not sorted out her feelings, if you really can't give up, then wait, be patient, accompany him by his side, love her, and care about him. The girl's heart is very soft, you have been paying for him like this, he will know, he will be moved now, maybe he will fall in love with you in the future, don't worry, as long as you keep not giving up and work hard, I believe you will be able to be with him

13 answers2024-02-09

This has been made very clear, he doesn't like you, you are just a spare tire for her, not worthy of your love, from the situation you described, her sexual relationship is more complicated, and there is a serious game obsession, this kind of person is very troublesome, even if you become one day, there are many hidden dangers in the later marriage, just keep a good distance from her, find a reliable girl to be safe, or you can also use her as a spare tire.

49 answers2024-02-09

I think that if one person doesn't like the other, too much coercion will have a bad effect. You should be empathetic, what would happen to you if a woman who didn't like you kept chasing you? Will you accept her because of her sincerity? >>>More