我正在尝试为Google柱形图创建一个mysql pivot样式查询。我希望“借记”数据显示在“transDesc”描述下,但它总是显示为0.我对这个平台还是比较新的,所以任何人都可以告诉我,我是否在正确的轨道上?
SELECT
view_monthly_chart.pay_month, view_monthly_chart.transDesc AS Transaction,
IF(view_monthly_chart.transDesc = 'Bills', `debit`, 0) AS bills,
IF(view_monthly_chart.transDesc = 'Misc', `debit`, 0) AS misc,
IF(view_monthly_chart.transDesc = 'Inc', `debit`, 0) AS inc,
IF(view_monthly_chart.transDesc = 'Bank Trans', `debit`, 0) AS bank_trans
FROM view_monthly_chart
GROUP BY view_monthly_chart.pay_month, view_monthly_chart.transDesc
ORDER BY view_monthly_chart.pay_id DESC
查询基于视图:
select `t1`.`pay_id` AS `pay_id`,`t3`.`pay_month` AS `pay_month`,`t2`.`Desc` AS `transDesc`,floor(sum(`t1`.`debit`)) AS `debit`
from ((`transactions`.`tbltransaction` `t1`
left join `transactions`.`tbltransid` `t2`
on((`t1`.`trans_id` = `t2`.`id`)))
left join `transactions`.`tblpayid` `t3`
on((`t1`.`pay_id` = `t3`.`pay_id`)))
where (`t2`.`Desc` is not null)
group by `t1`.`pay_id`,`t3`.`pay_month`,`t2`.`Desc`
order by `t1`.`pay_id` desc limit 24
答案 0 :(得分:0)
在# coding: utf8
import json
import re
import textwrap
from flask import Flask
from flask import request
app = Flask(__name__)
text_color_in_chat = "#000000"
@app.route('/')
def hello_world():
content = textwrap.dedent("""\
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script type="text/javascript" charset="utf-8">
function change_color(t) {
var url = "/route/to/change_color";
var data = {color: $('#chat-color').val()};
$.post(url, data);
}
</script>
<div>
Check your color in chat:
<input id="chat-color" type="color" value="<color>" onchange="change_color(this);">
</div>
""")
return content.replace("<color>", text_color_in_chat)
@app.route('/route/to/change_color', methods=['POST'])
def change_color():
new_color = request.form['color']
if re.match(r'^#[0-9a-f]{6,6}$', new_color):
global text_color_in_chat
text_color_in_chat = new_color
return json.dumps({'change_color': "OK"})
return json.dumps({'change_color': "Invalid color"})
if __name__ == '__main__':
app.run(debug=True)
语句中执行控制结构的ANSI SQL方法是使用SELECT
这就是:
CASE WHEN … THEN … ELSE … END