我有桌子:
SHOW COLUMNS FROM `darbuotojai`;
+--------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------+--------------+------+-----+---------+----------------+
| id | int(10) | NO | PRI | NULL | auto_increment |
| vardas | char(20) | YES | | NULL | |
| pavarde | char(30) | YES | | NULL | |
| email | char(100) | YES | | NULL | |
| pareigos | char(50) | YES | | NULL | |
| ilg_tel_nr | decimal(8,0) | NO | PRI | 0 | |
| trump_tel_nr | decimal(3,0) | NO | PRI | 0 | |
| inv_nr | char(10) | YES | | NULL | |
+--------------+--------------+------+-----+---------+----------------+
如何使用sql命令计算表中的列? 我如何识别它们?
答案 0 :(得分:1)
SELECT COUNT(*)
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_schema = 'database_name'
AND table_name = 'tbl_name'
答案 1 :(得分:1)
SELECT count(*)
FROM information_schema.columns
WHERE table_name = 'darbuotojai'
答案 2 :(得分:1)
SELECT count(*) FROM information_schema.`COLUMNS` C
WHERE table_name = 'your_table_name'
AND TABLE_SCHEMA = "your_db_name"
仅当表名存在于多个db
中时才需要TABLE_SCHEMA