Magento 2 - how to use count and group by clause in collectionMagento 2: Select Field From Collection QueryFilter Collection with result of previous collectionSimple query: group by customer & specific product attribute (shirt size) but how?Subselect as main_table on magento collectionGet first and last inovice # in every dateMagento 2 get 100 most recent orders?How to get a collection of sales_order_status_history models with a specific set of id's for parent_id column?Magento 2 SALES Order and REPORT Orders Export data qis inconsistentHow to write inner join query in collection method (magento2)?How to write Nested Query in Grid Collection _initSelect methodMagento2 How to get customer group from sales order item collection
Why does Hellboy file down his horns?
Optimising Table wrapping over a Select
Replacements for swear words
If a specific mass of air is polluted, will the pollution stick with it?
Who Can Help Retag This?
Repeating redundant information after dialogues, to avoid or not?
Password maker in c#
Referring to different instances of the same character in time travel
What explains 9 speed cassettes price differences?
Why is dry soil hydrophobic? Bad gardener paradox
Was adding milk to tea started to reduce employee tea break time?
Can I play a first turn Simic Growth Chamber to have 3 mana available in the second turn?
Credit union holding car note, refuses to provide details of how payments have been applied
Did any of the founding fathers anticipate Lysander Spooner's criticism of the constitution?
What would be the ideal melee weapon made of "Phase Metal"?
How can one write good dialogue in a story without sounding wooden?
What is this welding tool I found in my attic?
What's the minimum number of sensors for a hobby GPS waypoint-following UAV?
Was I subtly told to resign?
During copyediting, journal disagrees about spelling of paper's main topic
Is this floating-point optimization allowed?
Is Arc Length always irrational between two rational points?
Is Prophet from Facebook any different from a linear regression?
Assign media item to sitecore item using powershell script
Magento 2 - how to use count and group by clause in collection
Magento 2: Select Field From Collection QueryFilter Collection with result of previous collectionSimple query: group by customer & specific product attribute (shirt size) but how?Subselect as main_table on magento collectionGet first and last inovice # in every dateMagento 2 get 100 most recent orders?How to get a collection of sales_order_status_history models with a specific set of id's for parent_id column?Magento 2 SALES Order and REPORT Orders Export data qis inconsistentHow to write inner join query in collection method (magento2)?How to write Nested Query in Grid Collection _initSelect methodMagento2 How to get customer group from sales order item collection
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
i have order collection and want to this query result like
`SELECT `created_at`,COUNT(`entity_id`) FROM `sales_order_item` GROUP BY `created_at`;
i use this query
`$selectCollection=$this->ordercollection->create()->addFieldToSelect('entity_id')->addFieldToSelect('created_at');
$querycollection=$selectCollection->getSelect('COUNT(`entity_id`)')->group('created_at');`
But not work
Just i want to get how many orders come on each date or every day ?
magento2 collection count grouby
add a comment |
i have order collection and want to this query result like
`SELECT `created_at`,COUNT(`entity_id`) FROM `sales_order_item` GROUP BY `created_at`;
i use this query
`$selectCollection=$this->ordercollection->create()->addFieldToSelect('entity_id')->addFieldToSelect('created_at');
$querycollection=$selectCollection->getSelect('COUNT(`entity_id`)')->group('created_at');`
But not work
Just i want to get how many orders come on each date or every day ?
magento2 collection count grouby
add a comment |
i have order collection and want to this query result like
`SELECT `created_at`,COUNT(`entity_id`) FROM `sales_order_item` GROUP BY `created_at`;
i use this query
`$selectCollection=$this->ordercollection->create()->addFieldToSelect('entity_id')->addFieldToSelect('created_at');
$querycollection=$selectCollection->getSelect('COUNT(`entity_id`)')->group('created_at');`
But not work
Just i want to get how many orders come on each date or every day ?
magento2 collection count grouby
i have order collection and want to this query result like
`SELECT `created_at`,COUNT(`entity_id`) FROM `sales_order_item` GROUP BY `created_at`;
i use this query
`$selectCollection=$this->ordercollection->create()->addFieldToSelect('entity_id')->addFieldToSelect('created_at');
$querycollection=$selectCollection->getSelect('COUNT(`entity_id`)')->group('created_at');`
But not work
Just i want to get how many orders come on each date or every day ?
magento2 collection count grouby
magento2 collection count grouby
edited Jul 4 at 15:30
Abdul Pathan
3507 bronze badges
3507 bronze badges
asked Jul 4 at 13:25
HaFiz UmerHaFiz Umer
6131 silver badge13 bronze badges
6131 silver badge13 bronze badges
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Something like this
namespace XigenDemoBlockIndex;
/**
* Index class
*/
class Index extends MagentoFrameworkViewElementTemplate
/**
* Constructor
*
* @param MagentoFrameworkViewElementTemplateContext $context
* @param array $data
*/
public function __construct(
MagentoFrameworkViewElementTemplateContext $context,
MagentoFrameworkAppResourceConnection $resource,
array $data = []
)
$this->connection = $resource->getConnection();
$this->resource = $resource;
parent::__construct($context, $data);
public function getTestQuery()
$select = $this->connection
->select()
->from($this->resource->getTableName('sales_order_item'))
->reset(Zend_Db_Select::COLUMNS)
->columns(['created_at', new Zend_Db_Expr('COUNT(`sales_order_item`.`product_id`) as count')])
->group('created_at');
;
// SELECT `sales_order_item`.`created_at`, count(`sales_order_item`.`product_id`) FROM `sales_order_item` GROUP BY `created_at`
echo (string) $select;
$data = $this->connection->fetchAll($select);
foreach ($data as $item)
// ["created_at"]=> string(19) "2019-05-16 00:31:50"
// ["count"]=> string(1) "2"
var_dump($item);
die();
If you want to do it as part of a factory collection same methods apply. Just slightly different syntax.
Magento 2: Select Field From Collection Query
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
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: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f280831%2fmagento-2-how-to-use-count-and-group-by-clause-in-collection%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
Something like this
namespace XigenDemoBlockIndex;
/**
* Index class
*/
class Index extends MagentoFrameworkViewElementTemplate
/**
* Constructor
*
* @param MagentoFrameworkViewElementTemplateContext $context
* @param array $data
*/
public function __construct(
MagentoFrameworkViewElementTemplateContext $context,
MagentoFrameworkAppResourceConnection $resource,
array $data = []
)
$this->connection = $resource->getConnection();
$this->resource = $resource;
parent::__construct($context, $data);
public function getTestQuery()
$select = $this->connection
->select()
->from($this->resource->getTableName('sales_order_item'))
->reset(Zend_Db_Select::COLUMNS)
->columns(['created_at', new Zend_Db_Expr('COUNT(`sales_order_item`.`product_id`) as count')])
->group('created_at');
;
// SELECT `sales_order_item`.`created_at`, count(`sales_order_item`.`product_id`) FROM `sales_order_item` GROUP BY `created_at`
echo (string) $select;
$data = $this->connection->fetchAll($select);
foreach ($data as $item)
// ["created_at"]=> string(19) "2019-05-16 00:31:50"
// ["count"]=> string(1) "2"
var_dump($item);
die();
If you want to do it as part of a factory collection same methods apply. Just slightly different syntax.
Magento 2: Select Field From Collection Query
add a comment |
Something like this
namespace XigenDemoBlockIndex;
/**
* Index class
*/
class Index extends MagentoFrameworkViewElementTemplate
/**
* Constructor
*
* @param MagentoFrameworkViewElementTemplateContext $context
* @param array $data
*/
public function __construct(
MagentoFrameworkViewElementTemplateContext $context,
MagentoFrameworkAppResourceConnection $resource,
array $data = []
)
$this->connection = $resource->getConnection();
$this->resource = $resource;
parent::__construct($context, $data);
public function getTestQuery()
$select = $this->connection
->select()
->from($this->resource->getTableName('sales_order_item'))
->reset(Zend_Db_Select::COLUMNS)
->columns(['created_at', new Zend_Db_Expr('COUNT(`sales_order_item`.`product_id`) as count')])
->group('created_at');
;
// SELECT `sales_order_item`.`created_at`, count(`sales_order_item`.`product_id`) FROM `sales_order_item` GROUP BY `created_at`
echo (string) $select;
$data = $this->connection->fetchAll($select);
foreach ($data as $item)
// ["created_at"]=> string(19) "2019-05-16 00:31:50"
// ["count"]=> string(1) "2"
var_dump($item);
die();
If you want to do it as part of a factory collection same methods apply. Just slightly different syntax.
Magento 2: Select Field From Collection Query
add a comment |
Something like this
namespace XigenDemoBlockIndex;
/**
* Index class
*/
class Index extends MagentoFrameworkViewElementTemplate
/**
* Constructor
*
* @param MagentoFrameworkViewElementTemplateContext $context
* @param array $data
*/
public function __construct(
MagentoFrameworkViewElementTemplateContext $context,
MagentoFrameworkAppResourceConnection $resource,
array $data = []
)
$this->connection = $resource->getConnection();
$this->resource = $resource;
parent::__construct($context, $data);
public function getTestQuery()
$select = $this->connection
->select()
->from($this->resource->getTableName('sales_order_item'))
->reset(Zend_Db_Select::COLUMNS)
->columns(['created_at', new Zend_Db_Expr('COUNT(`sales_order_item`.`product_id`) as count')])
->group('created_at');
;
// SELECT `sales_order_item`.`created_at`, count(`sales_order_item`.`product_id`) FROM `sales_order_item` GROUP BY `created_at`
echo (string) $select;
$data = $this->connection->fetchAll($select);
foreach ($data as $item)
// ["created_at"]=> string(19) "2019-05-16 00:31:50"
// ["count"]=> string(1) "2"
var_dump($item);
die();
If you want to do it as part of a factory collection same methods apply. Just slightly different syntax.
Magento 2: Select Field From Collection Query
Something like this
namespace XigenDemoBlockIndex;
/**
* Index class
*/
class Index extends MagentoFrameworkViewElementTemplate
/**
* Constructor
*
* @param MagentoFrameworkViewElementTemplateContext $context
* @param array $data
*/
public function __construct(
MagentoFrameworkViewElementTemplateContext $context,
MagentoFrameworkAppResourceConnection $resource,
array $data = []
)
$this->connection = $resource->getConnection();
$this->resource = $resource;
parent::__construct($context, $data);
public function getTestQuery()
$select = $this->connection
->select()
->from($this->resource->getTableName('sales_order_item'))
->reset(Zend_Db_Select::COLUMNS)
->columns(['created_at', new Zend_Db_Expr('COUNT(`sales_order_item`.`product_id`) as count')])
->group('created_at');
;
// SELECT `sales_order_item`.`created_at`, count(`sales_order_item`.`product_id`) FROM `sales_order_item` GROUP BY `created_at`
echo (string) $select;
$data = $this->connection->fetchAll($select);
foreach ($data as $item)
// ["created_at"]=> string(19) "2019-05-16 00:31:50"
// ["count"]=> string(1) "2"
var_dump($item);
die();
If you want to do it as part of a factory collection same methods apply. Just slightly different syntax.
Magento 2: Select Field From Collection Query
answered Jul 4 at 23:24
Dominic XigenDominic Xigen
2,8001 gold badge4 silver badges15 bronze badges
2,8001 gold badge4 silver badges15 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- 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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f280831%2fmagento-2-how-to-use-count-and-group-by-clause-in-collection%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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