ホームページ  >  記事  >  データベース  >  mysql を持つ

mysql を持つ

黄舟
黄舟オリジナル
2017-01-16 13:10:381604ブラウズ

having
価格差が 200 を超える列をクエリします

select goods_id,(market_price - shop_price ) as chajia from goods having chajia>200;

押し出された商品の合計量をクエリします

select sum(goods_number*shop_price) from goods;

各列の下の商品のバックログを確認します

mysql> select cat_id ,sum(goods_number*shop_price) from goods group by cat_id;
+--------+------------------------------+
| cat_id | sum(goods_number*shop_price) |
+--------+------------------------------+
| 2 | 0.00 | 
| 3 | 356235.00 | 
| 4 | 9891.00 | 
| 5 | 29600.00 | 
| 8 | 4618.00 | 
| 11 | 790.00 | 
| 13 | 134.00 | 
| 14 | 162.00 | 
| 15 | 190.00 | 
+--------+------------------------------+

商品のバックログが 200 を超える列を確認します20,000

mysql> select cat_id ,(sum(goods_number*shop_price)) as dae from goods group by cat_id having dae > 20000;
+--------+-----------+
| cat_id | dae |
+--------+-----------+
| 3 | 356235.00 | 
| 5 | 29600.00 | 
+--------+-----------+
insert into result
values
('张三','数学',90),
('张三','语文',50),
('张三','地理',40),
('李四','语文',55),
('李四','政治',45),
('王五','政治',30);

2つ求める 不合格者の平均値

逆ロジック

select name,avg(score) from result group by name having (sum(score<60))>=2 ;

その2つは同等

select name,avg(score),sum(score<60) as guake from result group by name having guake>=2;

順ロジック(サブクエリ使用)

select name,avg(score)
from result
where name in ( 
select name from ( 
(select name ,count(*) as guake from result where score<60 group by name having guake>=2) as tmp 
)
)
group by name;

上記はmysqlの内容です、その他の関連コンテンツについては、PHP 中国語 Web サイト (www.php.cn) に注目してください。


声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
前の記事:mysqlの順序次の記事:mysqlの順序