select '1','1',1,1,'1','1','js' from dual union all
select '2','2',2,2,'2','2','bj' from dual union all
select '3','3',3,3,'3','3','sh' from dual union all
select '4','4',4,4,'4','4','gz' ;
select PRODUCTID as 產品編號,PRODUCTNAME,PRODUCTPRICE,QUANTITY,CATEGORY,DESCRIPTION,ORIGIN from productinfo1
select PRODUCTPRICE,productprice || '*' || 1.5 || '=' || productprice * 1.5 as new_productprice from productinfo;
select distinct substr(PRODUCTID,1,6) (as) 產品編號 from productinfo1 order by productid desc nulls last;
update productinfo2
set productname = null
where productid = 1;
select productname , productid from productinfo2 order by productname(產品名稱)(1) desc nulls last,2 desc;
select productname from productinfo2 where productid like '12'/productid is null //productid between 1 and 3//productid
in ('1','2','3')//productid > 1 and productid < 3//productid < 1 or productid > 3// not in//productid <> 3//like 's%'//
like 's_'
select productid,avg(productprice) from productinfo2 group by productid
merge into productinfo1
using productinfo
on (productinfo1.productid=productinfo.productid)
when matchded then update productinfo1
set productinfo1.productname=productinfo.productname,productinfo1.PRODUCTPRICE=productinfo.productprice
when not matched then insert into productinfo1
select * from productinfo
===
===
merge into productinfo1
using productinfo
on(productinfo1.productname=productinfo.productname)--不能是改更新的column
when matched then update
set productinfo1.productid=productinfo.productid
when not matched then insert
values(productinfo.PRODUCTID,productinfo.PRODUCTNAME,productinfo.PRODUCTPRICE,productinfo.QUANTITY,productinfo.CATEGORY,productinfo.DESCRIPTION,productinfo.ORIGIN)
select * from productinfo where productid = (select categoryid from categoryinfo where categoryname='4')//any (some)//
ALL
insert into categoryinfo(categoryid.categoryname)
select category,category from productinfo
select * from productinfo2 where productid < any (select categoryid from categoryinfo where categoryname='2')
連接查詢
select p.productname, p.productprice,c.categoryname
from productinfo p inner join categoryinfo c
on p.category=c.categoryid;
select productname, productprice,categoryname
from productinfo inner join categoryinfo
on category=categoryid;
===where 和 on left(right full) join/inner join
select productname, productprice, categoryname
from productinfo p
left join categoryinfo c on p.category = c.categoryid and c.categoryid = 1
select productname, productprice, categoryname
from productinfo p
left join categoryinfo c on p.category = c.categoryid where c.categoryid = 1
==
insert into usercalc select min(year(birthday)),min(month(birthday)),min(day(birthday)),min(salary),min(age) from user
union all select max(year(birthday)),max(month(birthday)),max(day(birthday)),max(salary),max(age) from user
union all select avg(year(birthday)),avg(month(birthday)),avg(day(birthday)),avg(salary),avg(age) from user;
delete from usercalc;
update usercalc set birthyear = (select min(year(birthday)) from user), birthmonth= (select min(year(birthmonth)) from user) where method = "min";
//這個在Java程序中很有用 使用jdbc連接時 對一個表的查詢要展現多行多列時 就可以如下使用 多行 uniom 多列增加select的字段
select "min" method,min(year(birthday)) birthyear,min(month(birthday)) birthmonth,min(day(birthday)) birthday,min(salary) salary,min(age) age from user
union all select "max" , max(year(birthday)),max(month(birthday)),max(day(birthday)),max(salary),max(age) from user
union all select "avg" ,avg(year(birthday)),avg(month(birthday)),avg(day(birthday)),avg(salary),avg(age) from user;