求一条mysql的语句

Web、Mail、Ftp、DNS、Proxy、VPN、Samba、LDAP 等基础网络服务
回复
rufen
帖子: 192
注册时间: 2008-05-29 13:06

求一条mysql的语句

#1

帖子 rufen » 2010-06-02 23:03

代码: 全选

+-----------------------------------------------+--------------------+
| name                                          | parent_category_id |
+-----------------------------------------------+--------------------+
| Contents                                      |                  0 | 
| Geographic                                    |                  0 | 
| GeometryCollection properties                 |                  1 | 
| Geometry constructors                         |                 31 | 
| Geometry properties                           |                 31 | 
| Geometry relations                            |                 31 | 
| LineString properties                         |                 31 | 
| MBR                                           |                 31 | 
| Point properties                              |                 31 | 
| Polygon properties                            |                 31 | 
| WKB                                           |                 31 | 
| WKT                                           |                 31 | 
| Account Management                            |                 32 | 
| Administration                                |                 32 | 
| Compound Statements                           |                 32 | 
| Data Definition                               |                 32 | 
| Data Manipulation                             |                 32 | 
| Data Types                                    |                 32 | 
| Functions                                     |                 32 | 
| Functions and Modifiers for Use with GROUP BY |                 32 | 
| Geographic Features                           |                 32 | 
| Language Structure                            |                 32 | 
| Table Maintenance                             |                 32 | 
| Transactions                                  |                 32 | 
| User-Defined Functions                        |                 32 | 
| Utility                                       |                 32 | 
| Bit Functions                                 |                 35 | 
| Comparison operators                          |                 35 | 
| Control flow functions                        |                 35 | 
| Date and Time Functions                       |                 35 | 
| Encryption Functions                          |                 35 | 
| Information Functions                         |                 35 | 
| Logical operators                             |                 35 | 
| Miscellaneous Functions                       |                 35 | 
| Numeric Functions                             |                 35 | 
| String Functions                              |                 35 | 
+-----------------------------------------------+--------------------+
name列取第一个字符,并分组count. 把count数大于等于3的那个字母对应的数据(即以这个字符开头的数据)全部输出来.
表是用的mysql中的help_category数据表.
头像
shinery
帖子: 1378
注册时间: 2009-07-22 22:23

Re: 求一条mysql的语句

#2

帖子 shinery » 2010-06-02 23:12

没有明白楼主的意思。
愿扣上你双手,至繁华浪处到沙丘。
rufen
帖子: 192
注册时间: 2008-05-29 13:06

Re: 求一条mysql的语句

#3

帖子 rufen » 2010-06-02 23:18

代码: 全选

select * from help_category where left(name,1) in (select left(name,1) from help_category group by left(name,1) having count(parent_category_id) > 2 ) order by left(name,1);
试出来了 o(∩_∩)o...哈哈
rufen
帖子: 192
注册时间: 2008-05-29 13:06

Re: 求一条mysql的语句

#4

帖子 rufen » 2010-06-02 23:20

代码: 全选

+------------------+-------------------------------+--------------------+-----+
| help_category_id | name                          | parent_category_id | url |
+------------------+-------------------------------+--------------------+-----+
|                6 | Control flow functions        |                 35 |     | 
|               32 | Contents                      |                  0 |     | 
|               16 | Comparison operators          |                 35 |     | 
|               21 | Compound Statements           |                 32 |     | 
|               36 | Data Definition               |                 32 |     | 
|               25 | Data Manipulation             |                 32 |     | 
|               29 | Date and Time Functions       |                 35 |     | 
|               19 | Data Types                    |                 32 |     | 
|               31 | Geographic Features           |                 32 |     | 
|               33 | Geometry properties           |                 31 |     | 
|               28 | Geometry relations            |                 31 |     | 
|               23 | GeometryCollection properties |                  1 |     | 
|               22 | Geometry constructors         |                 31 |     | 
|                1 | Geographic                    |                  0 |     | 
|               27 | Language Structure            |                 32 |     | 
|               12 | Logical operators             |                 35 |     | 
|               11 | LineString properties         |                 31 |     | 
+------------------+-------------------------------+--------------------+-----+
结果如上
tingjie
帖子: 20
注册时间: 2007-01-03 18:49

Re: 求一条mysql的语句

#5

帖子 tingjie » 2010-06-02 23:20

select * from help_category where substr(name, 1,1 ) in (select substr(name, 1, 1) FROM help_category group by substr(name, 1, 1) having count(substr(name, 1, 1) ) >= 3)
头像
shinery
帖子: 1378
注册时间: 2009-07-22 22:23

Re: 求一条mysql的语句

#6

帖子 shinery » 2010-06-02 23:35

牛叉,执行这样一条语句要多少时间
愿扣上你双手,至繁华浪处到沙丘。
gzbao9999
帖子: 627
注册时间: 2008-11-08 18:34

Re: 求一条mysql的语句

#7

帖子 gzbao9999 » 2010-07-16 11:21

学习下 :em01
气血鼓荡,身体发胀,偶飘上头,三时舒畅
头像
baicai271
帖子: 39
注册时间: 2009-07-21 21:00

Re: 求一条mysql的语句

#8

帖子 baicai271 » 2010-07-23 15:14

学习了 :em11
回复