Before doing the product horizontal display, have seen the comments said to use the cross-table.
The company recently needed to make a data summary of the order form, and colleagues gave a reference to the SQL
SELECT * FROM (select COUNT (1) as is locked from tbl_order where Orderlock = 1) as A,
(select COUNT (1) as unlocked from tbl_order where Orderlock = 0) as B,
(select COUNT (1) as is not shipped from Tbl_order where Pushstatus=1 and statusid=14) as C,
(select COUNT (1) as pending delivery from Tbl_order where Pushstatus=1 and statusid=14 and Isshipments=1) as D,
(select COUNT (1) as has been shipped from Tbl_order where statusid=4) as E,
(select COUNT (1) as is unassigned from tbl_order where Statusid = Pushstatus<>3 and pushstatus=0) as F,
(select COUNT (1) as has been assigned from Tbl_order where Pushstatus=1) as G,
(select COUNT (1) as has been pushed from Tbl_order where pushstatus=2) as H
Read the following SQL
SELECT
COUNT (case if Orderlock=1 then 1 ELSE NULL END) as ' locked ',
COUNT (case if orderlock=0 then 1 ELSE NULL END) as ' unlocked ',
COUNT (case if Pushstatus=1 and statusid=14 then 1 ELSE NULL END) as ' not shipped ',
COUNT (case if Pushstatus=1 and statusid=14 and Isshipments=1 then 1 ELSE NULL END) as ' pending shipment ',
COUNT (case if statusid=4 then 1 ELSE NULL END) as ' shipped ',
COUNT (case if Statusid = pushstatus<>3 and pushstatus=0 then 1 ELSE NULL END) as ' not assigned ',
COUNT (case if Pushstatus=1 then 1 ELSE NULL END) as ' allocated ',
COUNT (case if pushstatus=2 then 1 ELSE NULL END) as ' pushed '
From Tbl_order
The query table is used only once compared to the reference SQL above, and if there is a where condition that is more conducive to expansion.
Direct SQL Execution Plan reference:
This gap is obvious, and you are welcome to propose more optimized SQL.
SQL Cross Table