有没有办法扭转Oracle的Pivot函数使用的动态名称的顺序?
我有这个SQL语句,我必须对每个列重新别名,以便在末尾而不是在开头添加数字。这也要求我加倍引用实际的数据透视表列的名称。除了对列进行重新别名之外,还有更好的方法将数字附加到末尾吗?
SELECT PrimaryKey
, PRODUCT
, "1_SEQ" AS SEQ_1
, "1_TYP" AS TYP_1
, "1_STA" AS STA_1
, "1_RES" AS RES_1
, "2_SEQ" AS SEQ_2
, "2_TYP" AS TYP_2
, "2_STA" AS STA_2
, "2_RES" AS RES_2
, "3_SEQ" AS SEQ_3
, "3_TYP" AS TYP_3
, "3_STA" AS STA_3
, "3_RES" AS RES_3
, "4_SEQ" AS SEQ_4
, "4_TYP" AS TYP_4
, "4_STA" AS STA_4
, "4_RES" AS RES_4
, "5_SEQ" AS SEQ_5
, "5_TYP" AS TYP_5
, "5_STA" AS STA_5
, "5_RES" AS RES_5
FROM (
SELECT PrimaryKey
, ForeignKey
, Type
, STATUS
, RESULT
, PRODUCT
, ROW_NUMBER() OVER (PARTITION BY PrimaryKey ORDER BY ORDERNO, ForeignKey) NUM
FROM STG_tbl
)
PIVOT (
MAX(ForeignKey) AS SEQ
, MAX(Type) as TYP
, MAX(STATUS) AS STA
, MAX(RESULT) AS RES
FOR NUM IN (1,2,3,4,5)
)
答案 0 :(得分:0)
您可以添加别名,但这不会在列名后面加上数字:
@IBAction func toggleFlash() {
if let device = AVCaptureDevice.defaultDevice(withMediaType: AVMediaTypeVideo), device.hasTorch {
do {
try device.lockForConfiguration()
let torchOn = !device.isTorchActive
try device.setTorchModeOnWithLevel(1.0)
device.torchMode = torchOn ? .on : .off
device.unlockForConfiguration()
} catch {
print("error")
}
}