文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>SQL学习(一)

SQL学习(一)

时间:2011-03-03  来源:邪客

CREATE TABLE tablename(colname datatype [NOT NULL]

                                     {,colname datatype [NOT NULL]...}

                                     [,PRIMARY KEY (colname {,colname...})];

注: |,[] ,{}, ...在sql里不会出现,所以用其标记

二    简单的select语句:

select distinct ordno,x.cid,x.aid,x.pid,

                     .40*(x.qty*p.price)-.01*(c.dicnt+a.ercent)*(x.qty*p.price)as heji

                      from orders as x,customers as c,agents as a,products as p

                       where c.cid=x.cid and a.aid= x.aid and p.pid=x.aid;

x,c,a,p分别为orders,customers,agents,products的别名,关键字as可省略

ordno,cid, aid, pid ,heji为列名

heji 前面的as不可省略,他定义.40*(x.qty*p.price)-.01*(c.dicnt+a.ercent)*(x.qty*p.price)显示为heji

distinct确保检索后的每一行是唯一的

找出至少被两个顾客订购的产品的pid值

select distinct x1.pid

           from orders x1,orders x2

           where x1.pid=x2.pid and x1.pid<x2.pid;,

            

相关阅读 更多 +
排行榜 更多 +
方块枪战战场安卓版

方块枪战战场安卓版

飞行射击 下载
战斗火力射击安卓版

战斗火力射击安卓版

飞行射击 下载
空中防御战安卓版

空中防御战安卓版

飞行射击 下载