我有表,看起來像這樣如何獲得與行的總數新列值的MySQL
Date|Col1|Col2|Col3
01-01-2016|abc | | |
02-01-2016|xyz |188 | |
03-01-2016|100 |abc |155 |
我需要編寫一個查詢,會給我一個新列與列的總數每天的價值。
Date|Col1|Col2|Col3|count|
01-01-2016|abc | | | 1 |
02-01-2016|xyz |188 | | 2 |
03-01-2016|100 |abc | 155| 3 |
在我的實際數據中,我有大約30列,我需要指望。
'select *,count(*)from ... group by col1,col2,col3,...,colN' –
使用您的代碼;我在count列上得到的唯一值是1. – dgl
哦,所以03-01-2016會得到3,因爲3列有值?那麼你需要像'select *,(col1 <>'')+(col2 <>'')+等等......' –