The field location secret when the last function is used for querying after the SQL grouping

Source: Internet
Author: User

 

When the last function is used to query the SQL group, the field location will affect the sorting rule of the query results of each group. If the last function is used to obtain the last query result, effective sorting is very important.

 

Example:

Access View Design (1 ):

Select tower information. number, monitoring common data. time, monitoring general data. line name, monitoring common data. tower number, monitoring common data. tower name (monitoring common data. SIM card ID) as sim card number, monitoring common data. number of lightning strikes in Phase A, monitoring common data. number of lightning strikes in Phase B, monitoring common data. lightning strikes in Phase C
From monitoring conventional data inner join tower information on monitoring conventional data. SIM card id = tower information. SIM card number
Union select number, #1999-01-01 12:01:01 #, line name, Tower number, tower name, SIM card number, 0 as a lightning strikes, 0 as B lightning strikes, 0 as C-phase lightning strikes
From tower Information
Order by time;

 

Access View Design (II ):

Select tower information. number, monitoring common data. line name, monitoring common data. tower number, monitoring common data. tower name (monitoring common data. SIM card ID) as sim card number, monitoring common data. number of lightning strikes in Phase A, monitoring common data. number of lightning strikes in Phase B, monitoring common data. lightning strikes in Phase C
From monitoring conventional data inner join tower information on monitoring conventional data. SIM card id = tower information. SIM card number
Union select No., line name, tower no., tower no., SIM card No., 0 as a lightning strikes, 0 as B lightning strikes, 0 as C lightning strikes
From tower Information

Order by time;

 

 

Query through this view group:

Strsql = "select number, line name, Tower number, tower name, SIM card number ,"&_
"Last (number of lightning strikes on Phase A) Total number of lightning strikes on Phase ,"&_
"Last (number of lightning strikes in Phase B) as total number of lightning strikes in Phase B ,"&_
"Last (number of lightning strikes in Phase C) Total number of lightning strikes in Phase C "&_
"From view _ total number of tower lightning strikes "&_
"Group by number, line name, Tower number, tower name, SIM card number "&_
"Order by number, line name, Tower number, tower name, SIM card number"

 

 

Summary:

1. Use the ccess View Design (1). The [time] field is the second column. When the last function is used for grouping, the [total number of lightning strikes] will be sorted by date.

2. Use the ccess View Design (2). The [time] field is the end column. When grouping and using the last function to query, the [total number of lightning strikes] will be in the order of [total number of lightning strikes of Phase. This field is located in front of the column order.

 

If no sorting is specified for an SQL query, the values of fields are prioritized.

 

 

 

 

 

Author: Duan Liqing QQ: 14035344

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.