vb6 ADO查询 - 显示最受欢迎的项目

时间:2010-11-27 05:08:17

标签: vb6 ado

我在mySQL query - show most popular item找到的类似问题 但是我需要做些什么改动,对于VB6 ADO。

我想创建一个热门(最畅销)商品列表,没有日期范围。

表格的一个例子:

+------------+---------------------+-------+
| date       | item                |  qty  |
+------------+---------------------+-------+
| 2009-08-02 | Apple               |     5 |
| 2009-08-03 | Pear                |     2 |
| 2009-08-04 | Peach               |     4 |
| 2009-08-05 | Apple               |     1 |
| 2009-08-06 | Apple               |     3 |
+------------+---------------------+-------+

我需要的结果:

+------------+------------+-------+
| sl| item   |            | total |
+------------+------------+-------+
| 1 | Apple  |            |     9 |
| 2 | Peach  |            |     4 |
| 3 | Pear   |            |     2 |
+------------+------------+-------+

1 个答案:

答案 0 :(得分:1)

假设您已经有ADODB.Connection:

Dim oRS as New ADODB.Recordset
dim sSql as string

sSql = "SELECT item, SUM(qty) FROM myTable GROUP BY item ORDER BY Item"
oRS.Open sSql, oDBConn, adOpenForwardOnly, adLockReadOnly
Do While Not oRS.EOF
     '// Do something with the data'
     oRS.MoveNext
Loop
oRS.Close