如何结合不同条件的两个MySQL查询?

时间:2019-01-21 12:53:13

标签: php mysql

我有两个不同的MySQL查询。我需要将这两个查询合并为一个查询。我正在尝试获取给定日期的现金和信用卡总金额。

database data 预期结果如:

cash : 6666
card : 54657

SELECT SUM(Amount) as totalcash
FROM payment_details 
WHERE date(created) BETWEEN '2018-10-04' AND '2018-10-05' AND paymentMode="CASH";

SELECT SUM(Amount) as totalcard
FROM payment_details 
WHERE date(created) BETWEEN '2018-10-04' AND '2018-10-05' AND paymentMode="CARD";

1 个答案:

答案 0 :(得分:2)

您可以在下面尝试-

'use strict';
module.exports = (sequelize, DataTypes) => {
  const Service = sequelize.define('Service', {
    name: {
      type: DataTypes.STRING,
      allowNull: false
    }
  }, {});
  Service.associate = function (models) {
    Service.belongsTo(models.Experience, {
      foreignKey: 'id',
      onDelete: 'CASCADE'
    });
  };
  return Service;
};