ctf_web_sql(1)
select 列名 from 表名
select * from 表名
where 语句: 有条件的从表中选取数据。
select -列名称- from -表名- where -列/运算符/值-
order by: 语句用于根据指定的列对结果集进行排序,默认升序。
select…union(all)select…:联合查询,将两次或多次查询结果合并。
select cout(column_name) from table_name:函数返回指定列的值的数目。
select count(*) from table_name:函数返回表中的记录数。
select count(distinct column_name) from table_name: 函数返回指定列的不同值的数。
group by
例子:
| O_Id | OrderDate | OrderPrice | Customer |
|---|---|---|---|
| 1 | 2008/12/29 | 1000 | Bush |
| 2 | 2008/11/23 | 1600 | Carter |
| 3 | 2008/10/05 | 700 | Bush |
| 4 | 2008/09/28 | 300 | Bush |
| 5 | 2008/08/06 | 2000 | Adams |
| 6 | 2008/07/21 | 100 | Carter |
希望查询每个客户的总金额:
select customer,SUM(OrderPrice) from orders
group by customer
结果:
| Customer | SUM(OrderPrice) |
|---|---|
| Bush | 2000 |
| Carter | 1700 |
| Adams | 2000 |
round 函数用于把数值字段舍入为指定的小数位数
select round(column_name,decimals) from table_name
| 参数 | 描述 |
|---|---|
| column_name | 必需。要舍入的字段。 |
| decimals | 必需。规定要返回的小数位数。 |

1941

被折叠的 条评论
为什么被折叠?



