方法一,在程序中直接desc tablename,然后总行数就是字段数。
mysql> desc ysks+-------+---------------+-----
| Field | Type | Null
+-------+---------------+-----
| 单号 | int(11) | YES
| 金额 | decimal(10,2) | YES
| 已收 | decimal(10,2) | YES
| 日期 | bigint(20) | YES
| 名称 | varchar(10) | YES
| 余额 | decimal(10,2) | YES
| 备注 | varchar(10) | YES
| 品名 | varchar(10) | YES
+-------+---------------+-----
8 rows in set (0.06 sec)
mysql> select FOUND_ROWS()
+--------------+
| FOUND_ROWS() |
+--------------+
| 8 |
+--------------+
1 row in set (0.06 sec)
mysql>
方法二,通过系统表information_schema.`COLUMNS` ( mysql5以上版本支持)。
mysql> select count(*) from information_schema.`COLUMNS`-> where TABLE_SCHEMA='csdn'
-> and TABLE_NAME='ysks'
+----------+
| count(*) |
+----------+
| 8 |
+----------+
1 row in set (0.06 sec)
mysql>
一共加了三条数据
insert into pl_org_region(parent_id,region_sn,region_name,comments) values (0,'001','北京大区','无')insert into pl_org_region(parent_id,region_sn,region_name,comments) values (0,'002','西南大区','无')
insert into pl_store (store_sn,region_id,region_name) values ('P001',6,'北京大区')
查询语句改成:
SELECTp.region_id,
COUNT(p.region_id) AS cnt,
r.*
FROM
pl_org_region r
LEFT JOIN pl_store p ON r.region_id = p.region_id
GROUP BY
p.region_id
查询结果:
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)