解决方案 »
- 查询-插入问题。如何保证数据完整性?
- 自动增长类型怎么设置默认值
- mysql自动增加字段必须是什么类型呢?
- 两个表查询
- 我在导入数据的时候,mysql -uroot -proyasoft mccdb <d:/mccdb/mccdb_0519.sql,出现以下信息!
- DOS和数据库问题
- 如何写这些SQL语句(多表联合查询)
- 问一下:ms-sql 用的的是Transaction-sql,那么mysql用的是什么?
- 菜鸟问题: 在mysql中能不能定义boolean类型的字段?
- MySQL procedure cursor 如何遍历完
- 关于PostgreSQL的一个问题
- mysql select对游标的影响!100分!熟悉游标的进!
sum(if(Product=0,Quantity,null)) as Product0,
sum(if(Product=1,Quantity,null)) as Product1
from job_order
group by Job_datemysql> select * from job_order;
+------------+----------+---------+
| Job_date | Quantity | Product |
+------------+----------+---------+
| 2009-12-01 | 500 | 1 |
| 2009-12-01 | 100 | 0 |
| 2009-12-01 | 100 | 1 |
| 2009-11-01 | 600 | 0 |
| 2009-10-01 | 300 | 1 |
+------------+----------+---------+
5 rows in set (0.00 sec)mysql> select Job_date,
-> sum(if(Product=0,Quantity,null)) as Product0,
-> sum(if(Product=1,Quantity,null)) as Product1
-> from job_order
-> group by Job_date;
+------------+----------+----------+
| Job_date | Product0 | Product1 |
+------------+----------+----------+
| 2009-10-01 | NULL | 300 |
| 2009-11-01 | 600 | NULL |
| 2009-12-01 | 100 | 600 |
+------------+----------+----------+
3 rows in set (0.00 sec)mysql>
select Job_date,sum(if(Product=0,Quantity,null)) as Product0,sum(if(Product=1,Quantity,null)) as Product1 from job_order group by Job_date;