Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
i have here
table_A
| Customer ID | moneyspent |
001 50
002 30
003 20
003 20
002 30
i have seen a query that gets the sum of all moneyspent from table A
SELECT SUM(moneyspent) FROM table_A
but i want the results to be inserted in table B's column"totalspent" like this
table_B
| Customer ID | totalspent |
001 50
002 60
003 40
help pls.
thanks
Try this, it works I've checked:
INSERT INTO table_B (Customer_ID, totalspent)
(SELECT Customer_ID, sum(moneyspent) FROM table_A group by Customer_ID)
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
Below is my SQL table
| ID | Value |
| 1 | A1 A2 A3 |
I would like to delete the A3 in the column: Value. Is there any method to do this?
There's no way to edit/remove part of string, you just need to update whole cell. It's up tou you, how you'll prepare update data in your code.
SQL:
update tablename set Value = 'A1 A2' where ID=1
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
i have 3 tables which i want to combine in a empty table,
Table A contains:
a_id | name
1 | john
2 | mic
3 | rog
and
Table B contains:
b_id | name
10 | rims
11 | sara
and
Table c contains:
c_id | name
20 | johny
21 | sun
22 | rose
23 | pash
24 | ed
25 | ese
and i have one empty table D, which will have id's of all three above tables:
Table D columns are;
a_id | b_id | c_id
how can i insert all id's in table D? and
when i run query.
Select*from table_D
it should show all id's from table(a,b,c).
Your question is rather vague, because you don't specify what d looks like. Let me assume that you was a Cartesian product of all ids. This seems like a reasonable assumption. Then:
insert into d (a_id, b_id, c_id)
select a.a_id, b.b_id, c.c_id
from a cross join b cross join c;
Here is a rextester demonstrating it.
Here's what you ask for:
INSERT d
SELECT a.id, b.id, c.id
FROM a CROSS JOIN b CROSS JOIN c
Though I doubt it's what you want!
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
This is my sql outcome:
What I am trying to achieve is to show the garden and under that it shows the hose pipe ,lawn moar etc.
How to write the query?
If I understand you correct you would normaly do that somehow like that.
cat_id | parent_id | cat_name | cat order
1 0 Garden 1
2 1 Hose Pipe 1
3 1 Lawn Moar 2
in this case Garden for example would have the cat_id 1 and parent_id 0 and all subcategories have their own incremented id and the parent_id of garden, which would be 1 in this case!
then you can query for your categories and foreach of them query for the subcategories where the parent_id is the cat_id of the maincategory!
here you have a nice tutorial on how to display it recursive:
https://www.codexworld.com/dynamic-category-subcategory-tree-php-mysql/
that way you also only need to save the imagepath only once in your maincat!
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
i have the following query bellow
SELECT * FROM subcat where catid in (2) order by id desc
what i am trying to do is select one number only in catid i have ex:
1,2,3,4,5
this work but only when "catid" start with number "2" then have ","
example
ID | 1
subcat_name | PHP
catid | 2,3,4
ID | 2
subcat_name | ASP
catid | 5,2,3
ID | 3
subcat_name | MYSQL
catid | 6
ID | 4
subcat_name | C++
catid | 2
i want to select the subcat with only catid = 2
Try this
SELECT * FROM subcat where FIND_IN_SET(2,catid) order by id desc
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I intend that after selecting an option from a list, a new list appears according to the option selected.
But the second select list, sends a query to the database, depending on the choice list in the first select!
example:
table bd
| A | 1 |
| A | 2 |
| B | 3 |
| B | 4 |
first select
A or B
second select
if select A
1
2
if select B
3
4
A simple search for a filtered dropdown list brought me to the following code on GitHub which does a decent job explaining how to program one of these lists on your own. You can find it here.
Hope this helps.