亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 5317 | 回復(fù): 7
打印 上一主題 下一主題

mysql環(huán)比怎么寫? [復(fù)制鏈接]

論壇徽章:
1
數(shù)據(jù)庫技術(shù)版塊每日發(fā)帖之星
日期:2016-07-14 06:20:00
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2016-07-10 17:13 |只看該作者 |倒序瀏覽
這是我寫的sql語句:
select DATE_FORMAT(b.ACTUAL_TIME,'%Y') as 年度,
b.PAYMENT_DAYS as 月份,
b.PAY_MONEY as 本月繳費金額,
(select a.pay_money from tc_power_pay a where DATE_FORMAT(a.ACTUAL_TIME,'%Y')=2015
and a.payment_days=02 and a.BASE_STATION_ID=b.BASE_STATION_ID) as 上月份繳費金額,
(?) as 環(huán)比
from tc_power_pay b
where DATE_FORMAT(b.ACTUAL_TIME,'%Y')=2015 and  b.PAYMENT_DAYS=03 ORDER BY b.POWER_PAY_ID LIMIT 10;
在as環(huán)比前面的括號里面怎么寫sql語句,使得環(huán)比的結(jié)果為:(這個月/上個月)/上個月*100/%,這樣的結(jié)果

論壇徽章:
93
2015年辭舊歲徽章
日期:2019-10-10 10:51:15CU大;照
日期:2014-02-21 14:21:56CU十二周年紀念徽章
日期:2020-10-15 16:55:55CU大;照
日期:2014-02-21 14:22:07羊年新春福章
日期:2019-10-10 10:51:39CU大;照
日期:2019-10-10 10:55:38季節(jié)之章:春
日期:2020-10-15 16:57:40ChinaUnix元老
日期:2019-10-10 10:54:42季節(jié)之章:冬
日期:2019-10-10 10:57:17CU大;照
日期:2014-02-21 14:22:52CU大;照
日期:2014-03-13 10:40:30CU大牛徽章
日期:2014-02-21 14:23:15
2 [報告]
發(fā)表于 2016-07-11 09:38 |只看該作者
回復(fù) 1# lf361196


    如果是用的英文做 as 名字,可以直接在語句里使用,但是用中文我沒試過,你可以試一下看看效果怎樣,求分享哦。
比如是這樣:
  1. b.PAY_MONEY as this_month,
  2. (select a.pay_money from tc_power_pay a where DATE_FORMAT(a.ACTUAL_TIME,'%Y')=2015
  3. and a.payment_days=02 and a.BASE_STATION_ID=b.BASE_STATION_ID) as last_month,
  4. concat(format((this_month / last_month) / last_month * 100, 2), "%") as 環(huán)比
復(fù)制代碼

論壇徽章:
1
數(shù)據(jù)庫技術(shù)版塊每日發(fā)帖之星
日期:2016-07-14 06:20:00
3 [報告]
發(fā)表于 2016-07-11 16:00 |只看該作者
select DATE_FORMAT(b.ACTUAL_TIME,'%Y') as 年度,
b.PAYMENT_DAYS as 月份,
b.PAY_MONEY as this_month,
(select a.pay_money from tc_power_pay a where DATE_FORMAT(a.ACTUAL_TIME,'%Y')=2015 and
a.payment_days=02 and a.BASE_STATION_ID=b.BASE_STATION_ID) as last_month,
CONCAT((FORMAT(this_month /last_month) /last_month * 100,2), "%") as 環(huán)比率
from tc_power_pay b
where DATE_FORMAT(b.ACTUAL_TIME,'%Y')=2015 and  b.PAYMENT_DAYS=03 ORDER BY b.POWER_PAY_ID

用了你寫的這行環(huán)比的sql語句,數(shù)據(jù)庫執(zhí)行的時候還是出現(xiàn)了報錯,如下:
[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') /last_month * 100,2), "%") as 環(huán)比率
from tc_power_pay b
where DATE_FORMA' at line 6
請問這是什么報錯?


   

論壇徽章:
1
數(shù)據(jù)庫技術(shù)版塊每日發(fā)帖之星
日期:2016-07-14 06:20:00
4 [報告]
發(fā)表于 2016-07-11 16:11 |只看該作者
CONCAT((FORMAT(this_month-last_month) /last_month * 100,2), "%") as 環(huán)比率

應(yīng)該是這個月減去上個月:this_month - last_month而不是this_month/last_month


   

論壇徽章:
1
數(shù)據(jù)庫技術(shù)版塊每日發(fā)帖之星
日期:2016-07-14 06:20:00
5 [報告]
發(fā)表于 2016-07-11 16:23 |只看該作者
CONCAT((FORMAT(this_month-last_month)/last_month * 100,2), "%") as 環(huán)比率
我想問一下,你這里用format轉(zhuǎn)換,format不是對日期進行格式化嗎,而這里的this_month和last_month代表的是這個月的繳費金額跟上個月的繳費金額,是金額而不是日期格式,是不是有點問題呢?

   

論壇徽章:
93
2015年辭舊歲徽章
日期:2019-10-10 10:51:15CU大;照
日期:2014-02-21 14:21:56CU十二周年紀念徽章
日期:2020-10-15 16:55:55CU大;照
日期:2014-02-21 14:22:07羊年新春福章
日期:2019-10-10 10:51:39CU大;照
日期:2019-10-10 10:55:38季節(jié)之章:春
日期:2020-10-15 16:57:40ChinaUnix元老
日期:2019-10-10 10:54:42季節(jié)之章:冬
日期:2019-10-10 10:57:17CU大;照
日期:2014-02-21 14:22:52CU大;照
日期:2014-03-13 10:40:30CU大;照
日期:2014-02-21 14:23:15
6 [報告]
發(fā)表于 2016-07-11 18:07 |只看該作者
回復(fù) 5# lf361196


    報錯的話,你那抄的抄錯了啦,括號不對 當然我確實沒有測試,出錯很正常,你就參考一下用法而已。
你說的是 data_format 啦,這個用來操作時間的…… format 則不是。

論壇徽章:
1
數(shù)據(jù)庫技術(shù)版塊每日發(fā)帖之星
日期:2016-07-14 06:20:00
7 [報告]
發(fā)表于 2016-07-12 11:30 |只看該作者
今天終于做出來了,我在你寫的這個(b.PAY_MONEY as this_month,
(select a.pay_money from tc_power_pay a where DATE_FORMAT(a.ACTUAL_TIME,'%Y')=2015
and a.payment_days=02 and a.BASE_STATION_ID=b.BASE_STATION_ID) as last_month,
concat(format((this_month / last_month) / last_month * 100, 2), "%") as 環(huán)比 )  
基礎(chǔ)上改動了一下:
b.PAY_MONEY as this_month,
(select a.pay_money from tc_power_pay a where DATE_FORMAT(a.ACTUAL_TIME,'%Y')=2015
and a.payment_days=02 and a.BASE_STATION_ID=b.BASE_STATION_ID) as last_month,
concat(format(((b.PAY_MONEY / (select a.pay_money from tc_power_pay a where DATE_FORMAT(a.ACTUAL_TIME,'%Y')=2015
and a.payment_days=02 and a.BASE_STATION_ID=b.BASE_STATION_ID))-1) * 100, 2), "%") as 環(huán)比
這就對了。

謝謝你提供的用法語句,非常感謝!


   

論壇徽章:
93
2015年辭舊歲徽章
日期:2019-10-10 10:51:15CU大;照
日期:2014-02-21 14:21:56CU十二周年紀念徽章
日期:2020-10-15 16:55:55CU大;照
日期:2014-02-21 14:22:07羊年新春福章
日期:2019-10-10 10:51:39CU大;照
日期:2019-10-10 10:55:38季節(jié)之章:春
日期:2020-10-15 16:57:40ChinaUnix元老
日期:2019-10-10 10:54:42季節(jié)之章:冬
日期:2019-10-10 10:57:17CU大;照
日期:2014-02-21 14:22:52CU大;照
日期:2014-03-13 10:40:30CU大;照
日期:2014-02-21 14:23:15
8 [報告]
發(fā)表于 2016-07-12 16:48 |只看該作者
回復(fù) 7# lf361196


    客氣客氣,恭喜~~
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP