[英]SQL query to extract the part of matching SQL string
Let's consider a CLASS
and BILL
table.让我们考虑一个
CLASS
和BILL
表。
CLASS
table: CLASS
表:
Class![]() |
Description![]() |
---|---|
F ![]() |
Factory![]() |
H ![]() |
Headoffice![]() |
C001 ![]() |
Electrical![]() |
C002 ![]() |
Mechanical![]() |
C003 ![]() |
Civil![]() |
BILL
table: BILL
表:
BILL_NO ![]() |
DOCCLASS![]() |
---|---|
1 ![]() |
FC001 ![]() |
2 ![]() |
FC002 ![]() |
3 ![]() |
FC003 ![]() |
Description: Class
is a primary key.说明:
Class
是主键。 Let's say we created invoices by tagging different class from the CLASS
table.假设我们通过从
CLASS
表中标记不同的类来创建发票。
For example invoice 1 is created by tagging FCOO1
(ie. Factory and Electrical)例如,发票 1 是通过标记
FCOO1
(即工厂和电气)创建的
Problem: how to write a SQL query to get only COO1
part from FC001
of Invoice 1?问题:如何编写 SQL 查询以
FC001
发票 1 的FC001
中获取COO1
部分?
This SQL code is not working:此 SQL 代码不起作用:
Select
BILLDET.BILL_NO,
BILLDET.CLASS,
BILLDET.GLCODE,
CLASS.DESCRIPT
From
BILLDET
Full Join
CLASS On BILLDET.CLASS = CLASS.CLASS
Output:输出:
Bill NO![]() |
DESCRIPT![]() |
---|---|
1 ![]() |
FactoryElectrical![]() |
Thank you谢谢
Ugh, what a way to store data呃,这是一种什么方式来存储数据
WITH classx AS(
SELECT
c.class+n.class as class,
c.descript+n.descript as descript
FROM
class c
JOIN class n
ON
c.class LIKE 'c%' AND
n.class NOT LIKE 'c%'
)
SELECT * FROM bill JOIN classx ON bill.docclass = classx.class
select bill_no, Description
from
(
select c2.class + c1.class as keys, c2.description+c1.description as Description
from class c1, class c2
where c1.class LIKE 'c%' AND
c2.class NOT LIKE 'c%'
)as tab, bill
where keys = DOCCLASS;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.