Dab tsi yog pivot hauv SQL query?
Dab tsi yog pivot hauv SQL query?

Video: Dab tsi yog pivot hauv SQL query?

Video: Dab tsi yog pivot hauv SQL query?
Video: Niam xa me tub tuaj mus kawm nthawv 9/12/2017 2024, Kaum ib hlis
Anonim

SQL Server PIVOT tus neeg teb xov tooj rotates lub rooj-valued qhia. Nws hloov cov nqi tshwj xeeb hauv ib kem mus rau ntau kab hauv cov zis thiab ua cov kev sib sau ua ke ntawm txhua qhov seem seem.

Hais txog qhov no, pivot hauv SQL yog dab tsi?

SQL PIVOT thiab UNPIVOT yog ob tus neeg ua haujlwm sib raug zoo uas siv los hloov cov lus qhia rau lwm tus. PIVOT yog siv thaum peb xav hloov cov ntaub ntawv los ntawm kab theem mus rau kab ke thiab UNPIVOT yog siv thaum peb xav hloov cov ntaub ntawv los ntawm kab theem mus rau kab theem.

Tsis tas li ntawd, koj siv pivot thiab Unpivot hauv SQL li cas? Cov PIVOT nqe lus yog siv los hloov cov kab lus rau hauv kab, thaum lub UNPIVOT tus neeg teb xov tooj hloov cov kab rov qab mus rau kab. Rov qab a PIVOT nqe lus hais txog tus txheej txheem ntawm kev thov cov UNPIVOT tus neeg teb xov tooj mus rau qhov twb PIVOTED dataset thiaj li yuav rov qab tau cov ntaub ntawv qub.

Tsis tas li ntawd, cov lus pivot yog dab tsi?

PIVOT rotates lub rooj-valued qhia los ntawm tig cov cim qhov tseem ceeb ntawm ib kem nyob rau hauv cov lus qhia mus rau ntau kab nyob rau hauv cov zis. Lub syntax rau PIVOT muab tau yooj yim dua thiab nyeem tau ntau dua li cov syntax uas tej zaum yuav raug teev nyob rau hauv ib txoj kab ntawm SELECTCASE nqe lus.

Cov lus nug pivot yog dab tsi?

A PIAV query yog qhov tseem ceeb SELECT qhia cov kab uas koj xav tau thiab yuav ua li cas PIVOT thiab GROUP lawv. Sau a pivot query , ua raws li cov kauj ruam no. (3) Xaiv ib qho kev sib sau ua ke los tswj cov ntaub ntawv tsis sib xws, txawm tias koj tsis xav tias yuav xav tau. MAX, MIN, AVG, thiab SUM yog qhov ua tau.

Pom zoo: