sql語句 查詢記錄數
sql中查詢記錄數用count函數。
1、創建測試表,插入數據: create table test(id int)insert into test values (1)insert into test values (2)insert into test values (3)insert into test values (null)2、查詢記錄數為兩種,一種是count(*),一種是count(字段值): 測試一: select count(*) from test結果: 測試二: select count(id) from test結果: 說明:如果count(字段名)的字段中含有空值,則在count中不計數,而count(*)則是查詢全部的行數。
sql語句查詢每天添加的總數量
SELECT COUNT (1) addNum,
TO_CHAR (*_TIME,'YYYY-MM-DD') dateDay
FROM
BASE_USER baseUser
GROUP BY
TO_CHAR (
*_TIME,
'YYYY-MM-DD'
)
我的例子,每日增加的用戶數,,
但是如果某天沒有增加,這一天的數據是沒有查詢出來的
SQL語句 查詢 統計
* * from 學生表
* 學號,姓名,年齡 from 學生表
* 學號,姓名,年齡 from 學生表 where 年齡 between 18 and 20 and 系別='IS'
* 學號,姓名,年齡 from 學生表 where 姓名 like '李%' or 姓名 like '李%'
5 select distinct 學號 from 學生表 where 成績 6. select 姓名,年齡,系名 from 學生表 where 系 in ('IS','CS') order by 系名 ASC,姓名 desc
7 select count(*) from 學生表 where 系= 'IS'
8 select count(*) ,max(分數),min(分數)from 學生表
9 select 課程號,count(*),avg(分數) from 學生表 group by課程號
10 select 學號,count(*) from 學生表
11 select avg(分數),課程號 from 學生表 group by 課程號
12 select avg(分數),課程號 from 學生表 group by 課程號 order by avg(分數)
13 select count(*),學號 from 學生表 group by 學號
14 select count(*)a,學號 from 學生表 group by 學號 order by a
15 select 課程名稱,avg(分數) from 學生表 group by 課程名
16 select 課程標號,課程名稱,avg(分數) from 學生表 group by 課程號,課程名
17 select 課程名稱,avg(分數)a from 學生表 where a >70
18 select 姓名,count(*) a from 學生表 group by 姓名
19 select 學號,姓名,count(*) a from 學生表 group by 學號,姓名
20select 學生姓名,count(*) a from 學生表 where a>4 group by 學生姓名
如何用SQL語句查詢表名和行數
//查詢所有表明
select name from sysobjects where xtype='u'
select * from *
//查詢數據庫中所有的表名及行數
SELECT *, *
FROM sysobjects AS a INNER JOIN sysindexes AS b ON * = *
WHERE (* = 'u') AND (* IN (0, 1))
ORDER BY *,* DESC
//查詢所有的標明及空間占用量\行數
select
object_name(id) tablename,
8*reserved/1024 reserved,
rtrim(8*dpages)+'kb' used,
8*(reserved-dpages)/1024 unused,
8*dpages/1024-rows/1024*minlen/1024 free,
rows
--,*
from sysindexes
where indid=1
order by tablename,reserved desc