sql 旧版SOJ SQL语句

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql 旧版SOJ SQL语句相关的知识,希望对你有一定的参考价值。

SELECT COUNT(*) FROM OPTIKA.TAXPAYERMAIN1 WHERE TAXPAYREF = 'ZZ99999Z'

SELECT COUNT(*) FROM OPTIKA.TAXPAYERMAIN1
SELECT COUNT(*) FROM OPTIKA.TAXPAYERMAIN1

/* Taxpayers Tax Reference */

SELECT COUNT(*) FROM OPTIKA.TAXPAYERMAIN1 WHERE TAXPAYREF = 'ZZ99999Z'

SELECT COUNT(*) FROM OPTIKA.TAXPAYERMAIN1 WHERE 
TAXPAYREF LIKE '[A-Z][A-Z][ ][ ][ ][ ][0-9][A-Z]' OR
TAXPAYREF LIKE '[A-Z][A-Z][ ][ ][ ][ ][0-9][ ]' OR
TAXPAYREF LIKE '[A-Z][A-Z][ ][ ][ ][0-9][0-9][A-Z]' OR
TAXPAYREF LIKE '[A-Z][A-Z][ ][ ][ ][0-9][0-9][ ]' OR
TAXPAYREF LIKE '[A-Z][A-Z][ ][ ][0-9][0-9][0-9][A-Z]' OR
TAXPAYREF LIKE '[A-Z][A-Z][ ][ ][0-9][0-9][0-9][ ]' OR
TAXPAYREF LIKE '[A-Z][A-Z][ ][0-9][0-9][0-9][0-9][A-Z]' OR
TAXPAYREF LIKE '[A-Z][A-Z][ ][0-9][0-9][0-9][0-9][ ]' OR
TAXPAYREF LIKE '[A-Z][A-Z][0-9][0-9][0-9][0-9][0-9][A-Z]' OR
TAXPAYREF LIKE '[A-Z][A-Z][0-9][0-9][0-9][0-9][0-9][ ]'

SELECT COUNT(*) FROM OPTIKA.TAXPAYERMAIN1 WHERE 
TAXPAYREF NOT LIKE '[A-Z][A-Z][ ][ ][ ][ ][0-9][A-Z]' AND
TAXPAYREF NOT LIKE '[A-Z][A-Z][ ][ ][ ][ ][0-9][ ]' AND
TAXPAYREF NOT LIKE '[A-Z][A-Z][ ][ ][ ][0-9][0-9][A-Z]' AND
TAXPAYREF NOT LIKE '[A-Z][A-Z][ ][ ][ ][0-9][0-9][ ]' AND
TAXPAYREF NOT LIKE '[A-Z][A-Z][ ][ ][0-9][0-9][0-9][A-Z]' AND
TAXPAYREF NOT LIKE '[A-Z][A-Z][ ][ ][0-9][0-9][0-9][ ]' AND
TAXPAYREF NOT LIKE '[A-Z][A-Z][ ][0-9][0-9][0-9][0-9][A-Z]' AND
TAXPAYREF NOT LIKE '[A-Z][A-Z][ ][0-9][0-9][0-9][0-9][ ]' AND
TAXPAYREF NOT LIKE '[A-Z][A-Z][0-9][0-9][0-9][0-9][0-9][A-Z]' AND
TAXPAYREF NOT LIKE '[A-Z][A-Z][0-9][0-9][0-9][0-9][0-9][ ]'
SELECT COUNT(*) FROM OPTIKA.EMPLOYERMAIN1

/* Employers Tax Reference */

SELECT COUNT(*) FROM OPTIKA.EMPLOYERMAIN1 WHERE EMPRTAXR = 'ZZ99999Z'

SELECT COUNT(*) FROM OPTIKA.EMPLOYERMAIN1 WHERE 
EMPRTAXR LIKE '[A-Z][A-Z][ ][ ][ ][ ][0-9][A-Z]' OR
EMPRTAXR LIKE '[A-Z][A-Z][ ][ ][ ][ ][0-9][ ]' OR
EMPRTAXR LIKE '[A-Z][A-Z][ ][ ][ ][0-9][0-9][A-Z]' OR
EMPRTAXR LIKE '[A-Z][A-Z][ ][ ][ ][0-9][0-9][ ]' OR
EMPRTAXR LIKE '[A-Z][A-Z][ ][ ][0-9][0-9][0-9][A-Z]' OR
EMPRTAXR LIKE '[A-Z][A-Z][ ][ ][0-9][0-9][0-9][ ]' OR
EMPRTAXR LIKE '[A-Z][A-Z][ ][0-9][0-9][0-9][0-9][A-Z]' OR
EMPRTAXR LIKE '[A-Z][A-Z][ ][0-9][0-9][0-9][0-9][ ]' OR
EMPRTAXR LIKE '[A-Z][A-Z][0-9][0-9][0-9][0-9][0-9][A-Z]' OR
EMPRTAXR LIKE '[A-Z][A-Z][0-9][0-9][0-9][0-9][0-9][ ]'

SELECT COUNT(*) FROM OPTIKA.EMPLOYERMAIN1 WHERE 
EMPRTAXR NOT LIKE '[A-Z][A-Z][ ][ ][ ][ ][0-9][A-Z]' AND
EMPRTAXR NOT LIKE '[A-Z][A-Z][ ][ ][ ][ ][0-9][ ]' AND
EMPRTAXR NOT LIKE '[A-Z][A-Z][ ][ ][ ][0-9][0-9][A-Z]' AND
EMPRTAXR NOT LIKE '[A-Z][A-Z][ ][ ][ ][0-9][0-9][ ]' AND
EMPRTAXR NOT LIKE '[A-Z][A-Z][ ][ ][0-9][0-9][0-9][A-Z]' AND
EMPRTAXR NOT LIKE '[A-Z][A-Z][ ][ ][0-9][0-9][0-9][ ]' AND
EMPRTAXR NOT LIKE '[A-Z][A-Z][ ][0-9][0-9][0-9][0-9][A-Z]' AND
EMPRTAXR NOT LIKE '[A-Z][A-Z][ ][0-9][0-9][0-9][0-9][ ]' AND
EMPRTAXR NOT LIKE '[A-Z][A-Z][0-9][0-9][0-9][0-9][0-9][A-Z]' AND
EMPRTAXR NOT LIKE '[A-Z][A-Z][0-9][0-9][0-9][0-9][0-9][ ]'

/* Taxpayers Tax Reference */

SELECT COUNT(*) FROM OPTIKA.EMPLOYERMAIN1 WHERE TAXPAYREF = 'ZZ99999Z'

SELECT COUNT(*) FROM OPTIKA.EMPLOYERMAIN1 WHERE 
TAXPAYREF LIKE '[A-Z][A-Z][ ][ ][ ][ ][0-9][A-Z]' OR
TAXPAYREF LIKE '[A-Z][A-Z][ ][ ][ ][ ][0-9][ ]' OR
TAXPAYREF LIKE '[A-Z][A-Z][ ][ ][ ][0-9][0-9][A-Z]' OR
TAXPAYREF LIKE '[A-Z][A-Z][ ][ ][ ][0-9][0-9][ ]' OR
TAXPAYREF LIKE '[A-Z][A-Z][ ][ ][0-9][0-9][0-9][A-Z]' OR
TAXPAYREF LIKE '[A-Z][A-Z][ ][ ][0-9][0-9][0-9][ ]' OR
TAXPAYREF LIKE '[A-Z][A-Z][ ][0-9][0-9][0-9][0-9][A-Z]' OR
TAXPAYREF LIKE '[A-Z][A-Z][ ][0-9][0-9][0-9][0-9][ ]' OR
TAXPAYREF LIKE '[A-Z][A-Z][0-9][0-9][0-9][0-9][0-9][A-Z]' OR
TAXPAYREF LIKE '[A-Z][A-Z][0-9][0-9][0-9][0-9][0-9][ ]'

SELECT COUNT(*) FROM OPTIKA.EMPLOYERMAIN1 WHERE 
TAXPAYREF NOT LIKE '[A-Z][A-Z][ ][ ][ ][ ][0-9][A-Z]' AND
TAXPAYREF NOT LIKE '[A-Z][A-Z][ ][ ][ ][ ][0-9][ ]' AND
TAXPAYREF NOT LIKE '[A-Z][A-Z][ ][ ][ ][0-9][0-9][A-Z]' AND
TAXPAYREF NOT LIKE '[A-Z][A-Z][ ][ ][ ][0-9][0-9][ ]' AND
TAXPAYREF NOT LIKE '[A-Z][A-Z][ ][ ][0-9][0-9][0-9][A-Z]' AND
TAXPAYREF NOT LIKE '[A-Z][A-Z][ ][ ][0-9][0-9][0-9][ ]' AND
TAXPAYREF NOT LIKE '[A-Z][A-Z][ ][0-9][0-9][0-9][0-9][A-Z]' AND
TAXPAYREF NOT LIKE '[A-Z][A-Z][ ][0-9][0-9][0-9][0-9][ ]' AND
TAXPAYREF NOT LIKE '[A-Z][A-Z][0-9][0-9][0-9][0-9][0-9][A-Z]' AND
TAXPAYREF NOT LIKE '[A-Z][A-Z][0-9][0-9][0-9][0-9][0-9][ ]'
SELECT COUNT(*) FROM OPTIKA.TAXPAYERMAIN1

/* Selects Tax References where they equal a specific format */

SELECT COUNT(*) FROM OPTIKA.TAXPAYERMAIN1 WHERE 
TAXPAYREF LIKE '[A-Z][A-Z][ ][0-9][0-9][0-9]'

SELECT TAXPAYREF FROM OPTIKA.TAXPAYERMAIN1 WHERE 
TAXPAYREF LIKE '[A-Z][A-Z][ ][0-9][0-9][0-9]'

/* Updates Taxpayers Tax Reference Formats to a new field - SELECT TEST */

SELECT LEFT(TAXPAYREF,2)
+ SPACE(2)
+ RIGHT(RTRIM(TAXPAYREF),3)
+ SPACE(1)
AS NEW_TAXPAYREF
FROM OPTIKA.TAXPAYERMAIN1
WHERE TAXPAYREF LIKE '[A-Z][A-Z][ ][0-9][0-9][0-9]'

/* Updates Taxpayers Tax Reference Formats to a new field - UPDATE */

UPDATE OPTIKA.TAXPAYERMAIN1
SET NEWTAXR = LEFT(TAXPAYREF,2)
+ SPACE(2)
+ RIGHT(RTRIM(TAXPAYREF),3)
+ SPACE(1)
WHERE TAXPAYREF LIKE '[A-Z][A-Z][ ][0-9][0-9][0-9]'

/* Check the format of the updated field */

SELECT NEWTAXR FROM OPTIKA.TAXPAYERMAIN1
WHERE TAXPAYREF LIKE '[A-Z][A-Z][ ][0-9][0-9][0-9]'

/* Updates Taxpayers Tax Reference Number from the new field */

UPDATE OPTIKA.TAXPAYERMAIN1
SET TAXPAYREF = NEWTAXR
WHERE TAXPAYREF LIKE '[A-Z][A-Z][ ][0-9][0-9][0-9]'



SELECT COUNT(*) FROM OPTIKA.EMPLOYERMAIN1

/* Selects Employer References where they equal a specific format */

SELECT COUNT(*) FROM OPTIKA.EMPLOYERMAIN1 WHERE 
EMPRTAXR LIKE '[A-Z][A-Z][ ][0-9][0-9][0-9]'

SELECT EMPRTAXR FROM OPTIKA.EMPLOYERMAIN1 WHERE 
EMPRTAXR LIKE '[A-Z][A-Z][ ][0-9][0-9][0-9]'

/* Updates Employer Tax Reference Formats to a new field - SELECT TEST */

SELECT LEFT(EMPRTAXR,2)
+ SPACE(2)
+ RIGHT(RTRIM(EMPRTAXR),3)
+ SPACE(1)
AS NEW_EMPRTAXR
FROM OPTIKA.EMPLOYERMAIN1
WHERE EMPRTAXR LIKE '[A-Z][A-Z][ ][0-9][0-9][0-9]'

/* Updates Employer Tax Reference Formats to a new field - UPDATE */

UPDATE OPTIKA.EMPLOYERMAIN1
SET NEWTAXR = LEFT(EMPRTAXR,2)
+ SPACE(2)
+ RIGHT(RTRIM(EMPRTAXR),3)
+ SPACE(1)
WHERE EMPRTAXR LIKE '[A-Z][A-Z][ ][0-9][0-9][0-9]'

/* Check the format of the updated field */

SELECT NEWTAXR FROM OPTIKA.EMPLOYERMAIN1
WHERE EMPRTAXR LIKE '[A-Z][A-Z][ ][0-9][0-9][0-9]'

/* Updates Employer Tax Reference Number from the new field */

UPDATE OPTIKA.EMPLOYERMAIN1
SET EMPRTAXR = NEWTAXR
WHERE EMPRTAXR LIKE '[A-Z][A-Z][ ][0-9][0-9][0-9]'



/* Page Count Check per document type */

select taxpayref, taxyear, count(sequence)
from taxpayermain1 t, objectlist o
where t.recid = o.recid
and t.doctype = 'ITR-C'
group by taxpayref, taxyear
having count(sequence) <> 8
order by count(sequence) desc
/* Re-ordering pages in OBJECTLIST table (Acorde Context) depending upon document type field in TaxpayerMain1 table */

Update ObjectList Set Sequence = 9 Where Sequence = 3 And RecID In (Select RecID From TaxpayerMain1 Where DOCTYPE = 'ITR-C')
Update ObjectList Set Sequence = 10 Where Sequence = 4 And RecID In (Select RecID From TaxpayerMain1 Where DOCTYPE = 'ITR-C')
Update ObjectList Set Sequence = Sequence - 2 Where Sequence >= 5 And RecID In (Select RecID From TaxpayerMain1 Where DOCTYPE = 'ITR-C')


Select * From ObjectList Where RecID In (Select RecID From TaxpayerMain1 Where DOCTYPE = 'ITR-C')
/* Concatenation of two fields, one of the fields having a trailing space removed and the other being converted to a varchar type */

UPDATE OPTIKA.TAXPAYERMAIN1 SET TPYASSYR = LEFT(TAXPAYREF, 8) + CONVERT(VARCHAR(4), TAXYEAR)

以上是关于sql 旧版SOJ SQL语句的主要内容,如果未能解决你的问题,请参考以下文章

sql 旧版混合SQL语句

将旧版 SQL 查询转换为标准 SQL

旧版 sql 和标准 sql 之间的 BigQuery 表分区差异

如何将旧版 SQL BigQuery 转换为标准 SQL?

无法使用 R dplyr 在旧版 SQL 查询中引用 SQL 视图

无法在 Google BigQuery 中将此旧版 SQL 转换为标准 SQL