1、查询“001”课程比“002”课程成绩高的所有学生的学号; select a.S# from (select s#,score from SC where C#='001') a,(select s#,score from SC where C#='002') b where a.score>b.score and a.s#=b.s#; 2、查询平均成绩大于60分的同学的学号和平均成绩; select S#,avg(score) from sc group by S# having
查询所有数据库占用磁盘空间大小的SQL语句:
代码如下:select TABLE_SCHEMA, concat(truncate(sum(data_length)/1024/1024,2),’ MB’) as data_size,concat(truncate(sum(index_length)/1024/1024,2),’MB’) as index_sizefrom information_schema.tablesgroup by TABLE_SCHEMAorder by data_len
1.获取所有数据库名: SELECT Name FROM Master..SysDatabases ORDER BY Name 2.获取所有表名: SELECT Name FROM DatabaseName..SysObjects Where XType=’U’ ORDER BY Name XType=’U’:表示所有用户表; XType=’S’:表示所有系统表; 3.获取所有字段名: SELECT Name FROM SysColumns WHERE id=Object_Id(‘TableNa