SELECT
    t1.*,
    t2.enterprisename,
    t2.abbreviation,
    t2.phonenumber enterprisephonenumber,
    t3.agentnum,
    t4.enterprisename serviceenterprisename,
    t4.abbreviation serviceabbreviation,
    t4.phonenumber servicephonenumber,
    t5.agentnum serviceagentnum,
    t7.name saler_name,
    t8.itemid,
    t8.sku,
    t8.cardno,
    t9.itemno,
    t9.itemname,
    t9.model,
    t9.spec
FROM
    sa_serviceorder t1
        LEFT JOIN sys_enterprise t2 ON t1.sys_enterpriseid = t2.sys_enterpriseid
        AND t1.siteid = t2.siteid
        LEFT JOIN sa_agents t3 ON t2.sys_enterpriseid = t3.sys_enterpriseid
        AND t2.siteid = t3.siteid
        LEFT JOIN sys_enterprise t4 ON t1.sys_enterpriseid_service = t4.sys_enterpriseid
        AND t1.siteid = t4.siteid
        LEFT JOIN sa_agents t5 ON t4.sys_enterpriseid = t5.sys_enterpriseid
        AND t4.siteid = t5.siteid
        left join sys_hr t7 on t7.hrid=t1.saler_hrid and t7.siteid=t1.siteid
        left join (SELECT * FROM (SELECT *,ROW_NUMBER() OVER (PARTITION BY sa_serviceorderid ORDER BY sa_serviceorderitemsid ASC) AS rowno FROM sa_serviceorderitems) t WHERE rowno = 1) t8 on t8.sa_serviceorderid=t1.sa_serviceorderid and t8.siteid=t1.siteid
        left join plm_item t9 on t9.itemid=t8.itemid and t9.siteid=t8.siteid
	where  $where$