I have two tables orders and order_items I am trying to get the last order_sum for each day using an inner join but I am running into an error in my second join. Unknown column ‘o.last_order_date’ …
Tag: mysql
mysql gives a syntax error with many joins [closed]
it’s about an hour that I’m trying to understand why this query gives: syntax error near ‘WHERE players.player_user=1 AND players.player_status=0 GROUP BY players.playe’ on line 108 I have mysql 5.6….
How to Join two columns in same table
SELECT CAST(`last_charged_date` AS DATE) AS Date_time, COUNT(*) AS Charged_Count, SUM(last_charge_amt) AS Revenue FROM subscriber GROUP BY CAST(last_charged_date AS DATE) SELECT CAST(…
Select everything that has only one value in a relation
Okay, so here are my tables: tests: +—-+————+ | id | name | +—-+————+ | 1 | test-one | | 2 | test-two | | 3 | test-three | | 4 | test-four | | 5 | test-five | | …
Arithmetic operation on the subsets of results from a SQL groupby statement
I have a schema with sex(m/f),state_name(all states of a country), student_name,and education (phd,ms). I use following query to return total males or females in each category of education for every …
MySQL query result does not return some rows that should be in the result
This is a query that should return a match result of a lost item that has been found. According to my database below, I expect it to return two rows, but only one row is returned. Before I added the second rows in tbl_lost_items and tbl_found_items the result was an empty set. This is the result These are my …
How to compare column combinations from two tables?
I have two tables from different years, 2015 and 2016. Both tables have three columns as exampled below in table_2015: I want to see how many people had the same plan type between the years and how many people switched plan types. How do I go about doing this? Answer If customers are in each table only once a…
Getting wrong sum when using group by with inner join
With reference to this question (How to get the sum in a joined table when using group by – getting wrong results) I have two tables orders and order_items. I need to group the results by days. But I also need to get the sum of energy_used for each day from another table. When I try that using a join,
Generate a triangle of stars using mySQL recursive CTE
I’m trying to generate a triangle of stars in MYSQL that looks like this: ***** **** *** ** * I’m using the following code to do in MYSQL with recursive print_star(n) as ( select ‘*’ UNION …
Codeigniter MySQL filtering data as per user ID in the session
I have following function in my model to select records as per the user ID in the session. public function getOfficer() { $usr = $this->session->userdata(‘id_user’); $userArray = $…