mysql查询s开头的数据_数据库之基本查询示例(一)

本文演示了如何使用MySQL进行一系列查询操作,包括创建和插入数据到fruits和customers表,以及各种查询示例:如按条件查询价格、ID,模糊查询以特定字母开头的数据,去重,排序,分组统计等。
摘要由CSDN通过智能技术生成

1、创建所需表及插入数据

#创建数据表

mysql> create table fruits ( f_id char(10) not null, s_id int not null, f_name char(255) not null, f_price decimal(8,2) not null, primary key(f_id) );

#插入数据

mysql> insert into fruits(f_id,s_id,f_name,f_price)

-> values(‘a1‘,101,‘apple‘,‘5.2‘),

-> (‘b1‘,101,‘blackberry‘,‘10.2‘),

-> (‘bs1‘,102,‘orange‘,‘11.2‘),

-> (‘bs2‘,105,‘melon‘,‘8.2‘),

-> (‘t1‘,102,‘banana‘,‘10.3‘),

-> (‘t2‘,102,‘grape‘,‘5.3‘),

-> (‘o2‘,103,‘coconut‘,‘9.2‘),

-> (‘c0‘,101,‘cherry‘,‘3.2‘),

-> (‘a2‘,103,‘apricot‘,‘2.2‘),

-> (‘l2‘,104,‘lemon‘,‘6.4‘),

-> (‘b2‘,104,‘berry‘,‘7.6‘),

-> (‘m1‘,106,‘mango‘,‘15.7‘),

-> (‘m2‘,105,‘xbabay‘,‘2.6‘),

-> (‘t4‘,107,‘xbababa‘,‘2.6‘),

-> (‘m3‘,105,‘xxtt‘,‘11.6‘),

-> (‘b5‘,107,‘xxxx‘,‘3.6‘);

#创建第二个表

mysql> create table customers(

-> c_id int not null auto_increment,

-> c_name char(50) not null,

-> c_address char(50) null,

-> c_city char(50) null,

-> c_zip char(50) null,

-> c_contact char(50) null,

-> c_email char(50) null,

-> primary key(c_id)

-> );

#第二张表插入数据

mysql> insert into customers(c_id,c_name,c_address,c_city,c_zip,c_contact,c_email)

-> values(10001,‘RedHook‘,‘200 Street‘,‘Tianjin‘,‘300000‘,‘LiMing‘,‘LMing@163.com‘),

-> (1002,‘Stars‘,‘333 Fromage Lane‘,‘Dalian

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值