社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  DATABASE

带有join、groupby和having caluse的Mysql更新表

Bebekim Lim • 5 年前 • 1413 次点击  

选择查询

select sale_id, price,cONVERT(sum(price) , decimal(10,2)) as average, s.total from sale_items i
JOIN sales s ON s.id = i.sale_id
where s.currency = 'USD' 
and s.currency_total != 0 
and s.`deleted_at` is null
and i.`deleted_at` is null
group by s.id
having s.total <> average;  

更新我尝试的查询

    UPDATE sale_items i
JOIN sales s ON s.id = i.sale_id

SET i.price=(i.price / (s.total/s.currency_total)), i.total=(i.total / (s.total/s.currency_total)), i.total_tax=(i.total_tax / (s.total/s.currency_total))
where s.currency = 'USD' 
and s.currency_total != 0 
and s.`deleted_at` is null
and i.`deleted_at` is null
group by s.id
having s.total <> average;

错误:在'group by s.id having s.total<gt;average'附近使用的语法

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/54053
 
1413 次点击  
文章 [ 1 ]  |  最新文章 5 年前