0

嗨,我在提交数据库时遇到问题。我对 Firebird SQL 很陌生。但是我有一个查询,它创建一个表,然后提交它,然后插入它,提交它,查看数据,删除表,然后再次提交。我正在尝试动态地执行此操作,我可以点击一次执行按钮,然后它就会执行。有没有办法做到这一点?这是查询。

create table bp_customCollections(
       part_number varchar(255)
       ,part_description varchar(255)
       ,guided_reading_level varchar(255)
       ,lexile_level varchar(255)
       ,nonfiction_fiction varchar(255)
       ,on_hand varchar(255)
       ,default_vendor varchar(255)
       ,language varchar(255)
       ,product_price varchar(255)
       )

commit

insert into bp_customcollections(part_number, part_description,guided_reading_level,lexile_level,nonfiction_fiction, on_hand, default_vendor,language,product_price)
SELECT DISTINCT
part.num
,part.description
,COALESCE(grlmin.info,'Undefined')
,getLexile.lexile_level
,COALESCE(fnf.info,'')
,SUM(tag.qty)
,vendor.name
,customvarcharlong.info
,cast(product.price as decimal(10,2))

FROM PART

LEFT JOIN customset AS grlmin ON grlmin.recordid = part.id AND grlmin.customfieldid = 51 -- guided reading level minimum
LEFT JOIN getLexile on getLexile.lexile_partid = part.id and getLexile.lexile_partid = 61 -- lexile level
LEFT JOIN vendorparts on vendorparts.partid = part.id
LEFT JOIN vendor on vendor.id = vendorparts.vendorid
LEFT JOIN customset AS fnf on fnf.recordid = part.id AND fnf.customfieldid = 47  -- fiction/nofiction
LEFT JOIN tag on part.id = tag.partid
LEFT JOIN customvarcharlong on customvarcharlong.recordid = part.id and customvarcharlong.customfieldid = 56 -- language
LEFT JOIN product on product.partid = part.id
LEFT JOIN customset as resourceType on resourcetype.recordid = part.id
where vendorparts.defaultflag = 1
and resourcetype.info = 'Book'
GROUP BY part.num,part.description, COALESCE(grlmin.info,'Undefined'), COALESCE(fnf.info,''),getLexile.lexile_level, vendor.name, customvarcharlong.info,product.price
HAVING SUM(tag.qty) > 0

commit


select * from bp_customcollections
order by part_number

drop table bp_customCollections
commit
4

1 回答 1

1

创建一个视图,然后在需要时从中进行选择不是更容易吗?

create view vw_customCollections as
SELECT DISTINCT
part.num
,part.description
,COALESCE(grlmin.info,'Undefined')
,getLexile.lexile_level
,COALESCE(fnf.info,'')
,SUM(tag.qty)
,vendor.name
,customvarcharlong.info
,cast(product.price as decimal(10,2))
FROM PART
LEFT JOIN customset AS grlmin ON grlmin.recordid = part.id AND grlmin.customfieldid = 51 -- guided reading level minimum
LEFT JOIN getLexile on getLexile.lexile_partid = part.id and getLexile.lexile_partid = 61 -- lexile level
LEFT JOIN vendorparts on vendorparts.partid = part.id
LEFT JOIN vendor on vendor.id = vendorparts.vendorid
LEFT JOIN customset AS fnf on fnf.recordid = part.id AND fnf.customfieldid = 47  -- fiction/nofiction
LEFT JOIN tag on part.id = tag.partid
LEFT JOIN customvarcharlong on customvarcharlong.recordid = part.id and customvarcharlong.customfieldid = 56 -- language
LEFT JOIN product on product.partid = part.id
LEFT JOIN customset as resourceType on resourcetype.recordid = part.id
where vendorparts.defaultflag = 1
and resourcetype.info = 'Book'
GROUP BY part.num,part.description, COALESCE(grlmin.info,'Undefined'), COALESCE(fnf.info,''),getLexile.lexile_level, vendor.name, customvarcharlong.info,product.price
HAVING SUM(tag.qty) > 0

然后:

select *
from   vw_customCollections
order by  part_number
于 2013-05-28T14:52:46.357 回答