Home > Software engineering >  Consult with VB how to implement screening age range
Consult with VB how to implement screening age range

Time:09-21

I ask you, I want to realize the use of database data, count the number of cars in all ages, its calculated results displayed on the datagrid,
This statement should be how to write

CodePudding user response:

Group by group

CodePudding user response:

What is the meaning of this?

CodePudding user response:


 Private Sub Command1_Click () 
Dim NLD (1 To 4) As a String, the RS (1 To 4) As an Integer 'defines two array variable
NLD (1)="20 to 29,"
NLD (2)="30 to 39
"The NLD (3)="40 to 49,"
The NLD (4)="50 to 59,"
Adodc1. RecordSource="Select ID, age From car record"
Adodc1. Refresh
The Do While Not Adodc1. You. EOF
If Adodc1. You. Fields (" age ") & gt;=20 And Adodc1. You. Fields (" age ") & lt; 30 Then
RS (1)=RS (1) + 1
ElseIf Adodc1. You. Fields (" age ") & gt;=30 And Adodc1. You. Fields (" age ") & lt; 40 Then
RS (2)=RS (2) + 1
ElseIf Adodc1. You. Fields (" age ") & gt;=40 And Adodc1. You. Fields (" age ") & lt; 50 Then
RS (3)=RS (3) + 1
ElseIf Adodc1. You. Fields (" age ") & gt;=50 And Adodc1. You. Fields (" age ") & lt; 60 Then
RS (4) (4)=RS + 1
End the If
Adodc1. You. MoveNext
Loop
MSHFlexGrid1. Clear
With MSHFlexGrid1
The Cols=3
. Rows=5
. TextMatrix (0, 1)="ages"
TextMatrix (0, 2)="number"
ColWidth (0)=400
ColWidth (1)=1000
ColWidth (2)=1000
For I=1 To 4
TextMatrix (I, 1)=NLD (I)
TextMatrix (I, 2)=RS (I)
Next I
End With
End Sub

Database connection string slightly, car record data table is created at random, you can according to your data table,

CodePudding user response:

Don't bother 3 buildings, using the Partition function,

Assume that you already know how to use the Connection object to connect to the database, and use the cn object variables:

Rs. Open the "SELECT DISTINCTROW Partition ([age], 0, 60, 10) AS [s], Count (car. ID) AS [number] From car record GROUP BY Partition ([age], 0,60,10)", cn

The Set DataGrid1. The DataSource=rs

CodePudding user response:

Group by directly address, classified summary.

CodePudding user response:

Name age
==============
Zhang SAN 23
Li si 51
Fifty and 32
,
,



Select the convert (varchar (5), paragraph) + '0 -' + convert (varchar (5), paragraph) + '9' as ages, the number of the from
(
Select/10 age as age, count (distinct name) as the number of the from car table group by age/10
)

Give it a try
  • Related