SQL NOT GROUP BY












-1














Table columns:



ID | KEY_CODE | CONFIRMS | TYPE | ID_TX | AMOUNT | ADDR | TIMESTAMP


Response without my help:



'1', '38ajZshxdf', '6', 'i', 'jZshxdyAyzXucVYe', 
'0.00763766','3126ad1ec17eb114', '1541991745'


My query:



SELECT
id AS id,
CASE
WHEN confirms >= 3 THEN 1
ELSE 0
END AS status,
address,
monto
FROM
txs
WHERE
address IN ('38ajZshxdfrfEGfyAyzXucVY6YXRQSWaGe',
'18jkwUXwDYGXz9raoRdmGWjJFYQV3uu17Y',
'12p5H7QK6Jgtsy27pMNkdgTPjhtt6sN6bM')
GROUP BY
address, status


I need group rows by status (if confirm > 3 then 1 else 0), SQL query needs to return TOTAL amounts on 1 and 0 and specific addresses (ADDR).



Like this:



ADDR, HAVE(0.00000000), STATUS (1 | 0)









share|improve this question
























  • The error message is pretty clear. A GROUP BY must include every column that is not aggregated, so you can't use it the way you are with SELECT *, txs.id, and so forth. Find a good book or tutorial on SQL and read the section on aggregated columns and GROUP BY to learn basic syntax.
    – Ken White
    Nov 16 at 2:29










  • Possible duplicate of Error Code: 1055 incompatible with sql_mode=only_full_group_by
    – bummi
    Nov 16 at 2:34










  • @Bummi i did think, i'm fixing, give me few minutes... and tell u
    – Arcaela
    Nov 16 at 2:37
















-1














Table columns:



ID | KEY_CODE | CONFIRMS | TYPE | ID_TX | AMOUNT | ADDR | TIMESTAMP


Response without my help:



'1', '38ajZshxdf', '6', 'i', 'jZshxdyAyzXucVYe', 
'0.00763766','3126ad1ec17eb114', '1541991745'


My query:



SELECT
id AS id,
CASE
WHEN confirms >= 3 THEN 1
ELSE 0
END AS status,
address,
monto
FROM
txs
WHERE
address IN ('38ajZshxdfrfEGfyAyzXucVY6YXRQSWaGe',
'18jkwUXwDYGXz9raoRdmGWjJFYQV3uu17Y',
'12p5H7QK6Jgtsy27pMNkdgTPjhtt6sN6bM')
GROUP BY
address, status


I need group rows by status (if confirm > 3 then 1 else 0), SQL query needs to return TOTAL amounts on 1 and 0 and specific addresses (ADDR).



Like this:



ADDR, HAVE(0.00000000), STATUS (1 | 0)









share|improve this question
























  • The error message is pretty clear. A GROUP BY must include every column that is not aggregated, so you can't use it the way you are with SELECT *, txs.id, and so forth. Find a good book or tutorial on SQL and read the section on aggregated columns and GROUP BY to learn basic syntax.
    – Ken White
    Nov 16 at 2:29










  • Possible duplicate of Error Code: 1055 incompatible with sql_mode=only_full_group_by
    – bummi
    Nov 16 at 2:34










  • @Bummi i did think, i'm fixing, give me few minutes... and tell u
    – Arcaela
    Nov 16 at 2:37














-1












-1








-1







Table columns:



ID | KEY_CODE | CONFIRMS | TYPE | ID_TX | AMOUNT | ADDR | TIMESTAMP


Response without my help:



'1', '38ajZshxdf', '6', 'i', 'jZshxdyAyzXucVYe', 
'0.00763766','3126ad1ec17eb114', '1541991745'


My query:



SELECT
id AS id,
CASE
WHEN confirms >= 3 THEN 1
ELSE 0
END AS status,
address,
monto
FROM
txs
WHERE
address IN ('38ajZshxdfrfEGfyAyzXucVY6YXRQSWaGe',
'18jkwUXwDYGXz9raoRdmGWjJFYQV3uu17Y',
'12p5H7QK6Jgtsy27pMNkdgTPjhtt6sN6bM')
GROUP BY
address, status


I need group rows by status (if confirm > 3 then 1 else 0), SQL query needs to return TOTAL amounts on 1 and 0 and specific addresses (ADDR).



Like this:



ADDR, HAVE(0.00000000), STATUS (1 | 0)









share|improve this question















Table columns:



ID | KEY_CODE | CONFIRMS | TYPE | ID_TX | AMOUNT | ADDR | TIMESTAMP


Response without my help:



'1', '38ajZshxdf', '6', 'i', 'jZshxdyAyzXucVYe', 
'0.00763766','3126ad1ec17eb114', '1541991745'


My query:



SELECT
id AS id,
CASE
WHEN confirms >= 3 THEN 1
ELSE 0
END AS status,
address,
monto
FROM
txs
WHERE
address IN ('38ajZshxdfrfEGfyAyzXucVY6YXRQSWaGe',
'18jkwUXwDYGXz9raoRdmGWjJFYQV3uu17Y',
'12p5H7QK6Jgtsy27pMNkdgTPjhtt6sN6bM')
GROUP BY
address, status


I need group rows by status (if confirm > 3 then 1 else 0), SQL query needs to return TOTAL amounts on 1 and 0 and specific addresses (ADDR).



Like this:



ADDR, HAVE(0.00000000), STATUS (1 | 0)






sql syntax






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 at 5:20









marc_s

570k12811021250




570k12811021250










asked Nov 16 at 2:25









Arcaela

130110




130110












  • The error message is pretty clear. A GROUP BY must include every column that is not aggregated, so you can't use it the way you are with SELECT *, txs.id, and so forth. Find a good book or tutorial on SQL and read the section on aggregated columns and GROUP BY to learn basic syntax.
    – Ken White
    Nov 16 at 2:29










  • Possible duplicate of Error Code: 1055 incompatible with sql_mode=only_full_group_by
    – bummi
    Nov 16 at 2:34










  • @Bummi i did think, i'm fixing, give me few minutes... and tell u
    – Arcaela
    Nov 16 at 2:37


















  • The error message is pretty clear. A GROUP BY must include every column that is not aggregated, so you can't use it the way you are with SELECT *, txs.id, and so forth. Find a good book or tutorial on SQL and read the section on aggregated columns and GROUP BY to learn basic syntax.
    – Ken White
    Nov 16 at 2:29










  • Possible duplicate of Error Code: 1055 incompatible with sql_mode=only_full_group_by
    – bummi
    Nov 16 at 2:34










  • @Bummi i did think, i'm fixing, give me few minutes... and tell u
    – Arcaela
    Nov 16 at 2:37
















The error message is pretty clear. A GROUP BY must include every column that is not aggregated, so you can't use it the way you are with SELECT *, txs.id, and so forth. Find a good book or tutorial on SQL and read the section on aggregated columns and GROUP BY to learn basic syntax.
– Ken White
Nov 16 at 2:29




The error message is pretty clear. A GROUP BY must include every column that is not aggregated, so you can't use it the way you are with SELECT *, txs.id, and so forth. Find a good book or tutorial on SQL and read the section on aggregated columns and GROUP BY to learn basic syntax.
– Ken White
Nov 16 at 2:29












Possible duplicate of Error Code: 1055 incompatible with sql_mode=only_full_group_by
– bummi
Nov 16 at 2:34




Possible duplicate of Error Code: 1055 incompatible with sql_mode=only_full_group_by
– bummi
Nov 16 at 2:34












@Bummi i did think, i'm fixing, give me few minutes... and tell u
– Arcaela
Nov 16 at 2:37




@Bummi i did think, i'm fixing, give me few minutes... and tell u
– Arcaela
Nov 16 at 2:37












1 Answer
1






active

oldest

votes


















2














You are really wrong.. The snytax is not make much sense..



SELECT
*,
txs.id AS id,
CASE
WHEN txs.confirms >= 3 THEN 1
ELSE 0
END AS status,
address,
FORMAT(SUM(monto) ,8) AS balance,
tx,
fecha
FROM
txs
WHERE
txs.address IN ([SOME_LIST])

GROUP BY MIN(status)
ORDER BY status ASC


You are use * and you do Aggregate.. It's obviously Clear error.. Because All column you call must put in Group by and Your Group by with Min().. It can produce error too..




aggregate functions are not allowed in GROUP BY




So just take column what you need.



SELECT
txs.id AS id,
CASE
WHEN txs.confirms >= 3 THEN 1
ELSE 0
END AS status,
address,
FORMAT(SUM(monto) ,8) AS balance,
tx,
fecha
FROM
txs
WHERE
txs.address IN ([SOME_LIST])
GROUP BY
id,
(CASE
WHEN txs.confirms >= 3 THEN 1
ELSE 0
END),
address, tx, fecha
ORDER BY
(CASE
WHEN txs.confirms >= 3 THEN 1
ELSE 0
END) ASC


EDIT:



Because your status are condition column.. Put full expression instead..



CASE 
WHEN txs.confirms >= 3 THEN 1
ELSE 0
END AS status


This is your Status column.. Because this are condition column.. You cannot group by in same level.. So put your full expression in group by condition. And as you can see.. I put that expression in Group By and Order By full expression of your status column condition..



GROUP BY 
id,
(CASE
WHEN txs.confirms >= 3 THEN 1
ELSE 0
END), -----> This are Status Condition
address, tx, fecha
ORDER BY
(CASE
WHEN txs.confirms >= 3 THEN 1
ELSE 0
END) ASC -----------> and this too..





share|improve this answer























  • Need group BY status and address
    – Arcaela
    Nov 16 at 2:42






  • 1




    If you're going to post an answer, at least make the code in it correct. You missed columns in the GROUP BY, just like the poster did, and your suggested code will generate the same error.
    – Ken White
    Nov 16 at 2:44










  • I edited, check again pls, my english is not very well, but i try.
    – Arcaela
    Nov 16 at 3:16










  • Do you already try run my query? Just change some list with your data ..
    – dwir182
    Nov 16 at 3:21










  • No, but your code Group BY id and another fields, need group by address and status... because return many results.
    – Arcaela
    Nov 16 at 3:24











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53330576%2fsql-not-group-by%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














You are really wrong.. The snytax is not make much sense..



SELECT
*,
txs.id AS id,
CASE
WHEN txs.confirms >= 3 THEN 1
ELSE 0
END AS status,
address,
FORMAT(SUM(monto) ,8) AS balance,
tx,
fecha
FROM
txs
WHERE
txs.address IN ([SOME_LIST])

GROUP BY MIN(status)
ORDER BY status ASC


You are use * and you do Aggregate.. It's obviously Clear error.. Because All column you call must put in Group by and Your Group by with Min().. It can produce error too..




aggregate functions are not allowed in GROUP BY




So just take column what you need.



SELECT
txs.id AS id,
CASE
WHEN txs.confirms >= 3 THEN 1
ELSE 0
END AS status,
address,
FORMAT(SUM(monto) ,8) AS balance,
tx,
fecha
FROM
txs
WHERE
txs.address IN ([SOME_LIST])
GROUP BY
id,
(CASE
WHEN txs.confirms >= 3 THEN 1
ELSE 0
END),
address, tx, fecha
ORDER BY
(CASE
WHEN txs.confirms >= 3 THEN 1
ELSE 0
END) ASC


EDIT:



Because your status are condition column.. Put full expression instead..



CASE 
WHEN txs.confirms >= 3 THEN 1
ELSE 0
END AS status


This is your Status column.. Because this are condition column.. You cannot group by in same level.. So put your full expression in group by condition. And as you can see.. I put that expression in Group By and Order By full expression of your status column condition..



GROUP BY 
id,
(CASE
WHEN txs.confirms >= 3 THEN 1
ELSE 0
END), -----> This are Status Condition
address, tx, fecha
ORDER BY
(CASE
WHEN txs.confirms >= 3 THEN 1
ELSE 0
END) ASC -----------> and this too..





share|improve this answer























  • Need group BY status and address
    – Arcaela
    Nov 16 at 2:42






  • 1




    If you're going to post an answer, at least make the code in it correct. You missed columns in the GROUP BY, just like the poster did, and your suggested code will generate the same error.
    – Ken White
    Nov 16 at 2:44










  • I edited, check again pls, my english is not very well, but i try.
    – Arcaela
    Nov 16 at 3:16










  • Do you already try run my query? Just change some list with your data ..
    – dwir182
    Nov 16 at 3:21










  • No, but your code Group BY id and another fields, need group by address and status... because return many results.
    – Arcaela
    Nov 16 at 3:24
















2














You are really wrong.. The snytax is not make much sense..



SELECT
*,
txs.id AS id,
CASE
WHEN txs.confirms >= 3 THEN 1
ELSE 0
END AS status,
address,
FORMAT(SUM(monto) ,8) AS balance,
tx,
fecha
FROM
txs
WHERE
txs.address IN ([SOME_LIST])

GROUP BY MIN(status)
ORDER BY status ASC


You are use * and you do Aggregate.. It's obviously Clear error.. Because All column you call must put in Group by and Your Group by with Min().. It can produce error too..




aggregate functions are not allowed in GROUP BY




So just take column what you need.



SELECT
txs.id AS id,
CASE
WHEN txs.confirms >= 3 THEN 1
ELSE 0
END AS status,
address,
FORMAT(SUM(monto) ,8) AS balance,
tx,
fecha
FROM
txs
WHERE
txs.address IN ([SOME_LIST])
GROUP BY
id,
(CASE
WHEN txs.confirms >= 3 THEN 1
ELSE 0
END),
address, tx, fecha
ORDER BY
(CASE
WHEN txs.confirms >= 3 THEN 1
ELSE 0
END) ASC


EDIT:



Because your status are condition column.. Put full expression instead..



CASE 
WHEN txs.confirms >= 3 THEN 1
ELSE 0
END AS status


This is your Status column.. Because this are condition column.. You cannot group by in same level.. So put your full expression in group by condition. And as you can see.. I put that expression in Group By and Order By full expression of your status column condition..



GROUP BY 
id,
(CASE
WHEN txs.confirms >= 3 THEN 1
ELSE 0
END), -----> This are Status Condition
address, tx, fecha
ORDER BY
(CASE
WHEN txs.confirms >= 3 THEN 1
ELSE 0
END) ASC -----------> and this too..





share|improve this answer























  • Need group BY status and address
    – Arcaela
    Nov 16 at 2:42






  • 1




    If you're going to post an answer, at least make the code in it correct. You missed columns in the GROUP BY, just like the poster did, and your suggested code will generate the same error.
    – Ken White
    Nov 16 at 2:44










  • I edited, check again pls, my english is not very well, but i try.
    – Arcaela
    Nov 16 at 3:16










  • Do you already try run my query? Just change some list with your data ..
    – dwir182
    Nov 16 at 3:21










  • No, but your code Group BY id and another fields, need group by address and status... because return many results.
    – Arcaela
    Nov 16 at 3:24














2












2








2






You are really wrong.. The snytax is not make much sense..



SELECT
*,
txs.id AS id,
CASE
WHEN txs.confirms >= 3 THEN 1
ELSE 0
END AS status,
address,
FORMAT(SUM(monto) ,8) AS balance,
tx,
fecha
FROM
txs
WHERE
txs.address IN ([SOME_LIST])

GROUP BY MIN(status)
ORDER BY status ASC


You are use * and you do Aggregate.. It's obviously Clear error.. Because All column you call must put in Group by and Your Group by with Min().. It can produce error too..




aggregate functions are not allowed in GROUP BY




So just take column what you need.



SELECT
txs.id AS id,
CASE
WHEN txs.confirms >= 3 THEN 1
ELSE 0
END AS status,
address,
FORMAT(SUM(monto) ,8) AS balance,
tx,
fecha
FROM
txs
WHERE
txs.address IN ([SOME_LIST])
GROUP BY
id,
(CASE
WHEN txs.confirms >= 3 THEN 1
ELSE 0
END),
address, tx, fecha
ORDER BY
(CASE
WHEN txs.confirms >= 3 THEN 1
ELSE 0
END) ASC


EDIT:



Because your status are condition column.. Put full expression instead..



CASE 
WHEN txs.confirms >= 3 THEN 1
ELSE 0
END AS status


This is your Status column.. Because this are condition column.. You cannot group by in same level.. So put your full expression in group by condition. And as you can see.. I put that expression in Group By and Order By full expression of your status column condition..



GROUP BY 
id,
(CASE
WHEN txs.confirms >= 3 THEN 1
ELSE 0
END), -----> This are Status Condition
address, tx, fecha
ORDER BY
(CASE
WHEN txs.confirms >= 3 THEN 1
ELSE 0
END) ASC -----------> and this too..





share|improve this answer














You are really wrong.. The snytax is not make much sense..



SELECT
*,
txs.id AS id,
CASE
WHEN txs.confirms >= 3 THEN 1
ELSE 0
END AS status,
address,
FORMAT(SUM(monto) ,8) AS balance,
tx,
fecha
FROM
txs
WHERE
txs.address IN ([SOME_LIST])

GROUP BY MIN(status)
ORDER BY status ASC


You are use * and you do Aggregate.. It's obviously Clear error.. Because All column you call must put in Group by and Your Group by with Min().. It can produce error too..




aggregate functions are not allowed in GROUP BY




So just take column what you need.



SELECT
txs.id AS id,
CASE
WHEN txs.confirms >= 3 THEN 1
ELSE 0
END AS status,
address,
FORMAT(SUM(monto) ,8) AS balance,
tx,
fecha
FROM
txs
WHERE
txs.address IN ([SOME_LIST])
GROUP BY
id,
(CASE
WHEN txs.confirms >= 3 THEN 1
ELSE 0
END),
address, tx, fecha
ORDER BY
(CASE
WHEN txs.confirms >= 3 THEN 1
ELSE 0
END) ASC


EDIT:



Because your status are condition column.. Put full expression instead..



CASE 
WHEN txs.confirms >= 3 THEN 1
ELSE 0
END AS status


This is your Status column.. Because this are condition column.. You cannot group by in same level.. So put your full expression in group by condition. And as you can see.. I put that expression in Group By and Order By full expression of your status column condition..



GROUP BY 
id,
(CASE
WHEN txs.confirms >= 3 THEN 1
ELSE 0
END), -----> This are Status Condition
address, tx, fecha
ORDER BY
(CASE
WHEN txs.confirms >= 3 THEN 1
ELSE 0
END) ASC -----------> and this too..






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 16 at 3:29

























answered Nov 16 at 2:39









dwir182

1,368618




1,368618












  • Need group BY status and address
    – Arcaela
    Nov 16 at 2:42






  • 1




    If you're going to post an answer, at least make the code in it correct. You missed columns in the GROUP BY, just like the poster did, and your suggested code will generate the same error.
    – Ken White
    Nov 16 at 2:44










  • I edited, check again pls, my english is not very well, but i try.
    – Arcaela
    Nov 16 at 3:16










  • Do you already try run my query? Just change some list with your data ..
    – dwir182
    Nov 16 at 3:21










  • No, but your code Group BY id and another fields, need group by address and status... because return many results.
    – Arcaela
    Nov 16 at 3:24


















  • Need group BY status and address
    – Arcaela
    Nov 16 at 2:42






  • 1




    If you're going to post an answer, at least make the code in it correct. You missed columns in the GROUP BY, just like the poster did, and your suggested code will generate the same error.
    – Ken White
    Nov 16 at 2:44










  • I edited, check again pls, my english is not very well, but i try.
    – Arcaela
    Nov 16 at 3:16










  • Do you already try run my query? Just change some list with your data ..
    – dwir182
    Nov 16 at 3:21










  • No, but your code Group BY id and another fields, need group by address and status... because return many results.
    – Arcaela
    Nov 16 at 3:24
















Need group BY status and address
– Arcaela
Nov 16 at 2:42




Need group BY status and address
– Arcaela
Nov 16 at 2:42




1




1




If you're going to post an answer, at least make the code in it correct. You missed columns in the GROUP BY, just like the poster did, and your suggested code will generate the same error.
– Ken White
Nov 16 at 2:44




If you're going to post an answer, at least make the code in it correct. You missed columns in the GROUP BY, just like the poster did, and your suggested code will generate the same error.
– Ken White
Nov 16 at 2:44












I edited, check again pls, my english is not very well, but i try.
– Arcaela
Nov 16 at 3:16




I edited, check again pls, my english is not very well, but i try.
– Arcaela
Nov 16 at 3:16












Do you already try run my query? Just change some list with your data ..
– dwir182
Nov 16 at 3:21




Do you already try run my query? Just change some list with your data ..
– dwir182
Nov 16 at 3:21












No, but your code Group BY id and another fields, need group by address and status... because return many results.
– Arcaela
Nov 16 at 3:24




No, but your code Group BY id and another fields, need group by address and status... because return many results.
– Arcaela
Nov 16 at 3:24


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53330576%2fsql-not-group-by%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

ComboBox Display Member on multiple fields

Is it possible to collect Nectar points via Trainline?