select 五种子句顺序 where 条件 group by 分组 having 把结果进行再次筛选 order by 排序 limit 取出条目 统计函数 max(列名) 求最大 min(列名) 求最小 sum(列名) 求总和 avg(列名) 求平均 count(*) 求总行数 上面是5个统计函数,单独使用,意义不大,要和group by配合起来使用才有意义. 例: 帮我一次计算完,每个栏目下的库存量. group by分组查询 select cat_id,sum(g…
create table as select * from和insert into select from两种表复制语句区别 create table targer_table as select * from source_table insert into target_table(column1,column2) select column1,column2 from source_table 以上两句都是将源表source_table的记录插入到目标表target_table,但两句又…
select into from和insert into select from两种表复制语句都是将源表source_table的记录插入到目标表target_table,但两句又有区别. 第一句(select into from)要求目标表target_table不存在,因为在插入时会自动创建. select * into target_table from source_table; 第二句(insert into select from)要求目标表target_table存在,由于目标表已…
SQL SELECT TOP, LIMIT, ROWNUM 子句 SQL SELECT TOP 子句 SELECT TOP 子句用于规定要返回的记录的数目. SELECT TOP 子句对于拥有数千条记录的大型表来说,是非常有用的. 注释:并非所有的数据库系统都支持 SELECT TOP 子句. SQL Server / MS Access 语法 SELECT TOP number|percent column_name(s) FROM table_name; MySQL 和 Oracle 中的…
select 可以包含很复杂,很丰富的逻辑,最能考验一个人的逻辑思维能力和sql语句的掌握程度,我是这么认为,以前的很多次面试几乎都死在它手上,所以才有了今天的这篇日志,下定决心把它学好. where 表达式 我们要这样理解,表达式放在表中的哪一行成立,哪一行就取出来 =,>,<,>=,<=,!=/<>,and,or,between and,in,not group by 分组,一般和统计函数配合使用才有意义 max,min,avg,count,sum having 表…