SELECT COUNT(*) FROM (SELECT t.* from ( SELECT p.*,p.id descId from package_channel_price_plan p as a where a.sys_default=0 UNION SELECT c.*,c.id descId from package_commodity_main_info as b LEFT JOIN package_channel_price_plan as c on b.plan_code=c.plan_code where 1=1 and b.commodity_code = ? ) as t where 1=1 and t.plan_status = ? order by descId=? desc, t.updated_time DESC) TOTAL 这个ssql 错在哪
时间: 2024-02-10 11:29:14 浏览: 140
Event filter with query SELECT * FROM __InstanceModificationEvent WITHIN
这个 SQL 语句中的错误在于使用了 "as" 关键字来给子查询中的表起别名,但是在子查询中不能使用 "as" 关键字来为表起别名。正确的写法应该是直接使用表名来引用子查询的结果。以下是修正后的 SQL 语句:
SELECT COUNT(*) FROM (SELECT t.* from (
SELECT p.*,p.id descId from package_channel_price_plan p
where p.sys_default=0
UNION
SELECT c.*,c.id descId from package_commodity_main_info b
LEFT JOIN package_channel_price_plan c on b.plan_code=c.plan_code
where 1=1 and b.commodity_code = ?
) t
where 1=1 and t.plan_status = ?
order by descId=? desc, t.updated_time DESC) TOTAL
阅读全文