繁体   English   中英

如何连接一张表中的两列

[英]how to join two columns from one table

表名库;

id    item    price
1     book    13$
2     book    0
3     book    0
4     book    12$
5     PEN     0
6     PEN     5$
7     PEN     0

是否可以从表库中获得以下结果

id   Item    price
1    book    13$
4    book    12$
5    Pen     0
7    Pen     0

谢谢你的帮助

一种方法是使用where子句:

where (item = book and price > 0) or
      (item = pen and price = 0)

我不是 100% 确定这就是你要找的。

要获得问题的确切结果,请对标题使用双引号 ( " " )。

对于id >= 5将项目值设为 initipped。

在 where 条件中使用单引号( ' ' ),显然 item 列是string类型,而价格是alpha-numeric0,12$ ..等)

select id "id", decode(sign(id-4),1,initcap(item),item) "Item", price "price"
  from library
 where (item = 'book' and price != '0') or (item = 'PEN' and price = '0')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM