Home > database >  MSSQL optimization, a great god optimization statement
MSSQL optimization, a great god optimization statement

Time:09-18

Query 1
 
SELECT id, nick_name, avatar, cuRealType real_due_time, bond, payGoods,
(SELECT ISNULL (SUM (stars)/COUNT (id), 0) AS Expr1
The FROM dbo. Dt_app_evaluate
The WHERE (manager_id=Anderson, d)) AS the evaluate,
(SELECT COUNT (id) AS Expr1
The FROM dbo. Dt_app_follow
The WHERE (manager_id=Anderson, d)) AS follow,
(SELECT TOP (1) shopName
The FROM dbo. Dt_app_attestation
The WHERE (status=1) AND (user_id=Anderson d)
The ORDER BY id DESC) AS shopName,
(SELECT TOP (1) shopLogo
The FROM dbo. Dt_app_attestation AS dt_app_attestation_2
The WHERE (status=1) AND (user_id=Anderson d)
The ORDER BY id DESC) AS shopLogo,
(SELECT TOP (1) shopContent
The FROM dbo. Dt_app_attestation AS dt_app_attestation_1
The WHERE (status=1) AND (user_id=Anderson d)
The ORDER BY id DESC) AS shopContent
The FROM dbo. Dt_users AS a

Query 2
 
The SELECT Anderson d, a.n ick_name, a.a vatar, a.c uRealType, a.r eal_due_time, a. ond, Amy polumbo ayGoods, ISNULL (SUM (b.s tars)/COUNT (b.i d), 0) AS the evaluate, COUNT (c.i d) AS follow, d.s hopName, d.s hopLogo,
D.s hopContent
The FROM dbo. Dt_users AS a LEFT OUTER JOIN
Dbo. Dt_app_evaluate AS b ON b.m anager_id=Anderson d LEFT OUTER JOIN
Dbo. Dt_app_follow AS c ON c. anager_id=Anderson d LEFT OUTER JOIN
(SELECT TOP (1) user_id, shopName, shopLogo, shopContent
The FROM dbo. Dt_app_attestation
The WHERE (status=1)
The ORDER BY id DESC) AS d ON d.u ser_id=Anderson d
GROUP BY Anderson, d, a.n ick_name, a.a vatar, a.c uRealType, a.r eal_due_time, a. ond, Amy polumbo ayGoods, d.s hopName, d.s hopLogo, d.s hopContent

The above query is more efficient?
Is there a more optimized statement?

CodePudding user response:

Which high efficiency running once you know that, but a likely outcome of the second and first, because
 (SELECT TOP (1) user_id, 
ShopName,
ShopLogo,
ShopContent
The FROM dbo. Dt_app_attestation
The WHERE (status=1)
The ORDER BY id DESC) as d

The data is likely d.u ser_id=Anderson, d
  • Related