查询语句感悟

`test2`表
  • 1.select * from table的本质其实是因为table里面有数据,我们此处的*可以是table表里面的任何数据
  • 2.如果我们需要查询table2里面的所有数据,一般是select * from test2
  • 3.其实也可以这样select * from (select * from test2) as tmp切记,此处必须给(select * from test2)一个别名。他本质相当于是一个表名。
  • 4.那么我们要查询某个字段值,可以如下图所示select id,intfrom (select * from test2) as tmp
  • 5.如果要查询的某个字段是关键字,比如此处的(int)我们可以用键盘左上角的按个单引号``引起来
图片.png

如果需要从多个表中的数据取值,然后对这些值做查询处理,可以按照以下语法

select * from (
    select min(price) as price ,commodity_id from mall_sku group by commodity_id
    union all
    select price as price,commodity_id from mall_commodity where is_sku=0 group by commodity_id 
) as temp_table order by price
  • 需要注意的是内部多个sql查询字段的顺序必须保持一致
    sql查询
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容